编程语言
首页 > 编程语言> > python-pkl文件的简单使用

python-pkl文件的简单使用

作者:互联网

import _pickle as pickle

if __name__ == '__main__':
    a = [1, 2, 3]
    # 以二进制的形式打开文件
    with open("./1.pkl", "wb") as f:
        # 将列表a序列化后写入文件
        pickle.dump(a, f)
    with open("./1.pkl", 'rb') as f:
        # 反序列化解析成列表a
        a = pickle.load(f)
    print(a, a.__class__)  # [1, 2, 3] <class 'list'>

标签:__,文件,python,open,序列化,pickle,pkl
来源: https://blog.csdn.net/xidianbaby/article/details/97761283