python使用shelve报错:db type could not be determined
调用shelve模块时,我自己先创建了一个shelve_sample的文件,调试的时候提示:dbm.error: db type could not be determined
原代码如下:
1 f = shelve.open('shelve_sample') 2 f['key'] = {'a': 1, 'b': 2} 3 f.close()
报错如下:

解决方法:
删除自己创建shelve_sample文件,调用shelve会自动生成shelve_sample.bak、shelve_sample.dat、shelve_sample.dir三份文件。
shelve是一个对象持久化保存方法,将对象保存到文件里面,一般来说对象的保存和恢复都是通过shelve来进行的。
你的问题是test.txt已经存在,并且格式与shelve不符,所以提示 “db type could not be determined”
解决方法: 删除/home/luo/python/test.txt文件,首次运行后会自动生成该文件。
该解决方法来自于:https://blog.csdn.net/lk326604467/article/details/84785277

浙公网安备 33010602011771号