1. 程式人生 > 程式設計 >搭建公司私有MAVEN倉庫的方法

搭建公司私有MAVEN倉庫的方法

#序列化:將原來的字典、列表等內容轉化為一個字串資料型別
#為什麼需要序列化呢?
    # 資料儲存
    #網路傳輸(bytes傳輸)
#序列化: 資料型別(元組、列表等)----> 字串的過程
# 反序列化: 字串 ----> 資料型別(元組、列表等)的過程
#json *****
#pickle ****
#shelve ***
#json
    # 通用的序列化格式
    #只有很少的一部分資料型別能夠通過json轉化成字串
#pickle
    #所有的python中的資料型別都可以轉換成字串形式
    #pickle序列化的內容只有python能理解
    #反序列化依賴python程式碼
#shelve
    #序列化控制代碼
    #使用控制代碼直接操作,非常方便

#json (dumps:序列化方法 loads反序列化 )  在記憶體中操作
#數字 字串 列表 字典 可以通過json序列化
# dic 
={"k1":"v1","k2":2} # print(type(dic),dic) #<class 'dict'> {'k1': 'v1', 'k2': 2} 字典、列表等是單引號 # import json # str_d = json.dumps(dic) # print(type(str_d),str_d) #<class 'str'> {"k1": "v1", "k2": 2} 通過json轉化為str是雙引號 # dic_d = json.loads(str_d) # print(type(dic_d),dic_d) #<class
'dict'> {'k1': 'v1', 'k2': 2} #一次性寫和讀 #json (dump load) 和開啟檔案有關,先序列化在寫入檔案 # import json # dic ={'k1':'v1','k2':2} # with open('xuli',mode='w',encoding='utf-8') as f: # json.dump(dic,f) #xuli檔案內容為{"k1": "v1", "k2": 2} # with open('xuli',mode='r',encoding='utf-8') as f: # res = json.load(f) # print(type(res),res) #
<class 'dict'> {'k1': 'v1', 'k2': 2} # import json # dic = ['中國',1,'a',2] # # with open('xuli',mode='w',encoding='utf-8') as f: # # # json.dump(dic,f) #["\u4e2d\u56fd", 1, "a", 2] # # json.dump(dic,f,ensure_ascii=False) #["中國", 1, "a", 2] # with open('xuli',encoding='utf-8') as f: # res = json.load(f) # print(type(res),res) #<class 'list'> ['中國', 1, 'a', 2] #多次寫和讀(多次讀寫只能用dumps和loads dump和load只能一次性讀寫) import json # l = [{'k1':'111'},{'k2':'111'},{'k3':'111'}] # with open('file',mode='w') as f: # for dic in l: # str_dict = json.dumps(dic) # f.write(str_dict+'\n') # with open('file',mode='r+') as f: # l = [] # for line in f: # dic = json.loads(line.strip()) # print(dic) # l.append(dic) # print(l)