模块对象没有已打开的属性 [英] module object has no attribute open in shelve

查看:120
本文介绍了模块对象没有已打开的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的代码,

import shelve

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

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

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'

推荐答案

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

You imported a different module shelve, one that masks the standard library version.

做:

import shelve
print(shelve.__file__)

并将该文件移开,重命名或删除.

and move that file aside, rename it, or delete it.

这篇关于模块对象没有已打开的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆