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



以下是我的代码,

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'

> 您导入了不同的模块shelve,该模块屏蔽了标准库版本。

做:

import shelve
print(shelve.__file__)

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

最新更新