Python:pickle读写操作

#!/usr/bin/env python
# coding:UTF-8


"""
@version: python3.x
@author:曹新健
@contact: [email protected]
@software: PyCharm
@file: pickleDbFile.py
@time: 2018/9/25 23:11
"""
import pickle

#数据区start
zhangSan = {"name":"张三","age":18,"pay":200,"job":"学生"}
liSi = {"name":"李四","age":28,"pay":20000,"job":"程序员"}
LeeMin = {"name":"LeeMin","age":26,"pay":30000,"job":"销售"}

person = {}
person["zhangSan"] = zhangSan
person["liSi"] = liSi
person["LeeMin"] = LeeMin
#数据区end

#代码区
def pickleFile(db,file):
    with open(file,"wb") as dbFile:
        pickle.dump(db,dbFile)

def unpickeFile(file):
    with open(file,"rb") as dbFile:
        return pickle.load(dbFile)

if __name__ == "__main__":
    fileName = "people-pickle"
    #pickleFile(person,fileName)
    print(unpickeFile(fileName))

 

你可能感兴趣的:(Python基础知识,Python基础知识)