JSON 的加载处理
import json
字符串 -> JSON 对象
new_dict = json.loads(json_str)
print(new_dict)
print(type(new_dict))
JSON 对象 -> 字符串
test_dict = {'bigberg': [7600, {1: [['iPhone', 6300], ['Bike', 800], ['shirt', 300]]}]}
print(test_dict)
print(type(test_dict))
json_str = json.dumps(test_dict)
print(json_str)
print(type(json_str))
从文件读取 JSON
with open("../config/record.json",'r') as load_f:
load_dict = json.load(load_f)
print(load_dict)
JSON 写入文件
with open("../config/record.json","w") as write_f:
json.dump(new_dict, write_f)
print("加载入文件完成...")
随机数
import random
单个随机数
i = random.randint(A,B)
随机不重复列表
l = random.sample(range(A,B), COUNT)