Python Module 之pickle

pickle

'''
解决以下问题: 把数字写入文件后,读取出来是字符串,即写入什么就拿出来什么
存放: dump(targetData, openFile)
读取: load(openFile)
'''

Example:

import os, pickle
my_list = [1,4,3,12,3.14,"麻雀",["oneList"]]
# my_list = [1,4,3,12,3.14,5,6,7.899,"麻雀",["oneList"]]
aimPath = os.path.dirname(__file__)+"/tempPickle.pkl"
# a = help(pickle)
# print (a)

### 写入
with open(aimPath,"wb") as fw:
    pickle.dump(my_list, fw)
fw.close()
### 读取
with open(aimPath,"rb") as fr:
    contents = pickle.load(fr)
print (contents)
发布了48 篇原创文章 · 获赞 0 · 访问量 567

猜你喜欢

转载自blog.csdn.net/weixin_44286839/article/details/104219330