sketch.py #--*-- coding:utf-8 --*-- import pickle import nester man = [] other = [] try: data = open ("datafile.txt") for each_line in data: try: (role, line_spoken) = each_line.split(":", 1) line_spoken = line_spoken.strip() if role =…
import json,time # save data to json file def store(data): with open('data.json', 'w') as fw: # 将字典转化为字符串 # json_str = json.dumps(data) # fw.write(json_str) # 上面两句等同于下面这句 json.dump(data,fw) # load json data from file def load(): with open('data.json'…
会报错: UnicodeDecodeError: 'ascii' codec can't decode byte 0xa0 in position 3: ordinal not in range(128) 解决办法是添加encoding参数: pickle.load(f, encoding='iso-8859-1') 就能解决了…