2016-05-13 126 views
-1

當我重新安裝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應該創建該文件,如果它不存在。 –

回答

0

錯誤「FileNotFoundError:[錯誤2]沒有這樣的文件或目錄:‘data.dat文件’」會告訴你,它無法找到data.dat文件,請檢查文件位置。