为什么搁置如果我尝试打开一个刚刚创建的搁置文件会引发错误?搁置数据库类型无法确定,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