简体   繁体   English

尝试打开 pickle 文件时出现“int object 不可调用”?

[英]"int object is not callable" when trying to open pickle file?

I am working for a team of scientists and have been given a pickle file we'll call theFile.p .我在一个科学家团队工作,并获得了一个我们称之为theFile.p的 pickle 文件。 I am trying to open and load the Pickle file via我正在尝试通过打开并加载 Pickle 文件

opened_file = open("theFile.p", "rb")
loaded_data = pickle.load(opened_file)

but am getting the error但我收到错误

    loaded_data = pickle.load(opened_file)
                     ^^^^^^^^^^^^^^^^^^^^^
TypeError: 'int' object is not callable

Now I know that error means you either forgot an arithmetic operator somewhere or you declared a variable name that matches a built in function name (eg max = max(1, 2) ).现在我知道该错误意味着您要么在某处忘记了算术运算符,要么声明了一个与内置 function 名称匹配的变量名称(例如max = max(1, 2) )。 I am wondering if this means there is some sort of issue inside the theFile.p that's causing this error, and if so, how would I go about debugging the Pickle file if I can't even open it?我想知道这是否意味着theFile.p内部存在某种问题导致此错误,如果是这样,如果我什至无法打开它,我将如何调试 Pickle 文件 go? Or maybe it's an issue with me being on Python 3.11 and the pickle file was made on an older version Python?或者这可能是我在 Python 3.11 上的问题,而 pickle 文件是在旧版本 Python 上制作的?

Full traceback can be seen here完整的追溯可以在这里看到

Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py", line 1499, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/Users/NAME/Desktop/Todo/Test/main.py", line 12, in <module>
    main()
  File "/Users/NAME/Desktop/Todo/Test/main.py", line 7, in main
    loaded_file = pickle.load(opened_file)
                  ^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'int' object is not callable

Although I do not believe that this applies to you specifically, but I will still ask this to check, as anyone can make this mistake: have you imported the pickle plug-in?虽然我不相信这个具体适用于你,但我还是会问这个检查,因为任何人都会犯这个错误:你是否导入了 pickle 插件?

Updated: I was looking up how to load data with a pickle file and I came across many code excerpts with the same difference to yours.更新:我正在查找如何使用 pickle 文件加载数据,我发现许多代码摘录与您的代码摘录有相同的区别。 Now, I do not know whether this affects anything or not, but in all of the code excerpts I've seen, there has been no.p to open the pickle file.现在,我不知道这是否会影响任何事情,但在我看到的所有代码摘录中,都没有打开 pickle 文件的 no.p 。

import pickle

with open("theFile.p", "rb") as opened_file:
loaded_data = pickle.load(opened_file)

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

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