module object has no attribute open in shelve [duplicate]

 ̄綄美尐妖づ 提交于 2019-12-12 04:54:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!