标签:imp .json load amp python == 文件 pre div
1 import sys 2 import json 3 4 5 def main(): 6 # json dump 7 dump_data = {"api.version": sys.api_version} 8 with open("../data/data.json", "w") as f: 9 json.dump(dump_data, f) 10 # json load 11 with open("../data/data.json", "r") as f: 12 load_data = json.load(f) 13 print(type(load_data)) 14 print(load_data) 15 print(load_data[‘api.version‘]) 16 17 # json dumps 18 data = ["test", {"api.version": sys.api_version}] 19 dumps_data = json.dumps(data) 20 print(type(dumps_data)) 21 print(dumps_data) 22 # json loads 23 loads_data = json.loads(dumps_data) 24 print(type(loads_data)) 25 print(loads_data) 26 27 28 if __name__ == ‘__main__‘: 29 main()
data.json文件示例:
1 {"api.version": 1013}
标签:imp .json load amp python == 文件 pre div
原文地址:https://www.cnblogs.com/bigcat47/p/9800991.html