问题
Following is my code,
import shelve
sd = shelve.open("session.data")
When I try the same code in IDLE , I am not getting any error. But when running the script with this code, I am getting the following error,
Traceback (most recent call last):
File "try.py", line 3, in <module>
sd = shelve.open("session.data")
AttributeError: 'module' object has no attribute 'open'
回答1:
You imported a different module shelve
, one that masks the standard library version.
Do:
import shelve
print(shelve.__file__)
and move that file aside, rename it, or delete it.
来源:https://stackoverflow.com/questions/27102646/module-object-has-no-attribute-open-in-shelve