简体   繁体   English

通过 pickle 模块读取文件

[英]reading file by pickle module

good afternoon, saving list(dict(),dict(),dict()) struct with pickle module: but when reading I get, <class 'function'>?下午好,使用 pickle 模块保存 list(dict(),dict(),dict()) 结构:但是在阅读时我得到,<class 'function'>? and <function lesson at 0x00000278BA3A0D30> what am I doing wrong?和 <0x00000278BA3A0D30 的功能课程> 我做错了什么?

def lesson(user, date):
    with open(user+"_"+date+".data", 'wb') as file:
        pickle.dump(lesson, file)
    file.close()

def read(user, date):
    with open(user+"_"+date+".data", 'rb') as file:
        lesson = pickle.load(file)
    file.close()
    return(lesson)

I am using python 3.10.7我正在使用 python 3.10.7

"saving list(dict(),dict(),dict()) struct with pickle module". “使用泡菜模块保存list(dict(),dict(),dict())结构”。 No, you're not.不你不是。 You're saving the lesson function. See line 3 of your code.您正在保存lesson function。请参阅代码的第 3 行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM