Python的shelve模块小问题

来源:互联网 发布:ebrary电子书数据库 编辑:程序博客网 时间:2024/05/21 10:11
shelve模块:是个数据存储模块,可以在文件中存储数据  只需为其提供文件名     
在练习时,贴的代码:
<pre name="code" class="python">import shelvem = shelve.open(r'F:\python\Te.dat')

运行结果报错:
Traceback (most recent call last):
  File "E:/PythonTest/Bettery/shelve.py", line 8, in <module>
    import shelve
  File "E:\PythonTest\Bettery\shelve.py", line 9, in <module>
    m = shelve.open(r'F:\python\Tes.dat')
AttributeError: 'module' object has no attribute 'open'

然后百思不得其解,这两句很普通的语句,为何会提醒shelve模块没有open函数?


解决:后来发现是该文件命名是shelve.py,和这个模块的命名冲突了,导致运行报错。

       把文件名改为其他名字后就运行通过了。

    Btw,Python的文件命名不要和关键字冲突。

                                             
0 0
原创粉丝点击