使用pickle模块写入文件会导致错误

选择 | 换行 | 行号
  1. import pickle
  2. f = open("filepath/test.txt","w")
  3. f.write(" writing to a output file") # works
  4. pickle.dump([1,2,3],f) # fails with error "TypeError: write() argument must be str, not bytes"
  5. f.close()

pickle模块不是要解决在写入文件之前必须转换为字符串的问题吗?

标签: python

添加新评论