模块对象在搁置中没有打开属性

时间:2014-11-24 10:30:02

标签: python windows attributeerror shelve

以下是我的代码,

import shelve

sd = shelve.open("session.data")

当我在IDLE中尝试相同的代码时,我没有收到任何错误。 但是当使用此代码运行脚本时,我收到以下错误,

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 个答案:

答案 0 :(得分:2)

您导入了不同的模块shelve,该模块掩盖了标准库版本。

执行:

import shelve
print(shelve.__file__)

将该文件移到一边,重命名或删除它。