Shelve模块不工作

问题描述:

当我重新安装Python将其从AppData文件夹移动到Program Files时,看起来搁置模块不再工作,并且在拨打shelve.open()时收到以下错误消息。Shelve模块不工作

请帮忙!

>>> import shelve 
    >>> myShelf = shelve.open('data') 
    Traceback (most recent call last): 
     File "C:\Program Files\Python\lib\dbm\dumb.py", line 81, in _create 
     f = _io.open(self._datfile, 'r', encoding="Latin-1") 
    FileNotFoundError: [Errno 2] No such file or directory: 'data.dat' 

    During handling of the above exception, another exception occurred: 

    Traceback (most recent call last): 
     File "<pyshell#1>", line 1, in <module> 
     myShelf = shelve.open('data') 
     File "C:\Program Files\Python\lib\shelve.py", line 243, in open 
     return DbfilenameShelf(filename, flag, protocol, writeback) 
     File "C:\Program Files\Python\lib\shelve.py", line 227, in __init__ 
     Shelf.__init__(self, dbm.open(filename, flag), protocol, writeback) 
     File "C:\Program Files\Python\lib\dbm\__init__.py", line 94, in open 
     return mod.open(file, flag, mode) 
     File "C:\Program Files\Python\lib\dbm\dumb.py", line 303, in open 
     return _Database(file, mode, flag=flag) 
     File "C:\Program Files\Python\lib\dbm\dumb.py", line 69, in __init__ 
     self._create(flag) 
     File "C:\Program Files\Python\lib\dbm\dumb.py", line 83, in _create 
     with _io.open(self._datfile, 'w', encoding="Latin-1") as f: 
    PermissionError: [Errno 13] Permission denied: 'data.dat' 
    >>> 
+0

“FileNotFoundError:[Errno 2]没有这样的文件或目录:'data.dat'”。搁置模块工作正常,您只需确保您要阅读的文件存在。 – Evert

+1

尝试使用sudo运行python;建议因为您的错误中的权限被拒绝。 – PseudoAj

+0

Evert - shelve.open应该创建该文件,如果它不存在。 –

错误“FileNotFoundError:[错误2]没有这样的文件或目录:‘data.dat文件’”会告诉你,它无法找到data.dat文件,请检查文件位置。