2016-11-22 80 views
1

遇到很多嘗試在Python中使用擱架的問題。無法打開Python擱置對象

我能夠就好了剛纔創建一個新的貨架* .dbm對象,但現在,我得到了一個錯誤:

import shelve 
TESTING = shelve.open('C:\Users\dtruman\Documents\PROJECTS\testing.dbm','c',writeback=True) 

的Python返回以下神祕的錯誤:

Traceback (most recent call last): 
    File "<pyshell#7>", line 1, in <module> 
    TESTING = shelve.open('C:\Users\dtruman\Documents\PROJECTS\testing.dbm','c',writeback=True) 
    File "C:\Program Files (x86)\Python_2-7-11\lib\shelve.py", line 243, in open 
    return DbfilenameShelf(filename, flag, protocol, writeback) 
    File "C:\Program Files (x86)\Python_2-7-11\lib\shelve.py", line 227, in __init__ 
Shelf.__init__(self, anydbm.open(filename, flag), protocol, writeback) 
    File "C:\Program Files (x86)\Python_2-7-11\lib\anydbm.py", line 85, in open 
return mod.open(file, flag, mode) 
    File "C:\Program Files (x86)\Python_2-7-11\lib\dbhash.py", line 18, in open 
return bsddb.hashopen(file, flag, mode) 
    File "C:\Program Files (x86)\Python_2-7-11\lib\bsddb\__init__.py", line 364, in hashopen 
d.open(file, db.DB_HASH, flags, mode) 
DBError: (14, 'Bad address') 

這似乎是我試圖執行一個非常簡單的操作,但由於某種原因,Python不喜歡它。

回答

0

該文件路徑字符串中的「\ t」可能被解釋爲一個選項卡。嘗試使文件路徑爲原始字符串:

TESTING = shelve.open(r'C:\Users\dtruman\Documents\PROJECTS\testing.dbm','c',writeback=True)