解决 python3.x 报错:_pickle.UnpicklingError: the STRING opcode argument must be quoted
word_data = pickle.load(words_file_handler)
_pickle.UnpicklingError: the STRING opcode argument must be quoted
这是由于末尾的‘\r\n’和‘\n’ 不一致导致的,将load的文件修改为
original = "word_data.pkl"
destination = "word_data_win10.pkl"
content = ''
outsize = 0
with open(original, 'rb') as infile:
content = infile.read()
with open(destination, 'wb') as output:
for line in content.splitlines():
outsize += len(line) + 1
output.write(line + str.encode('\n'))
print("Done. Saved %s bytes." % (len(content)-outsize))