爲什麼擱置如果我嘗試打開一個剛剛創建的擱置文件會引發錯誤?擱置數據庫類型無法確定,whichdb不能識別gdb
import shelve
info_file_name = "/Users/bacon/myproject/temp/test.info"
info_file = shelve.open(info_file_name)
info_file['ok'] = 'wass'
info_file.close()
info_file = shelve.open(info_file_name) # raise exception db type could not be determined..
info_file.close()
我的情況下運行的Python 2.5的相關
精確的錯誤是提高是:
db type could not be determined
其通過anydbm.py
open
方法提高。
我知道它使用gdbm。我檢查了whichdb.py文件,並嘗試找出這個
# Read the start of the file -- the magic number
s16 = f.read(16)
s = s16[0:4]
# Convert to 4-byte int in native byte order -- return "" if impossible
(magic,) = struct.unpack("=l", s)
# Check for GNU dbm
if magic == 0x13579ace:
return "gdbm"
但在我的文件中的「魔術」號是324508367
(0x13579acf
)(只有最後一個數字的變化!)GDBM文件
我試着用另一種語言(紅寶石)打開文件,我能打開它沒有任何問題,因此這似乎是在whichdb.py錯誤試圖找出正確的DBM
使用Python 2.7.6此代碼的工作沒有問題。 – 2016-03-03 12:28:06
請編輯你的問題,以包括它正在提出的確切的錯誤。 – msw
在Windows 3.5上正常工作。 – msw