shelve: db type could not be determined

使用shelve持久序列化格式时,出现以下错误

shelve: db type could not be determined

代码如下:

import shelve

f = shelve.open('1234.txt')
names = ["qwe", "raqqin", "teest"]
info = {'nqq':'aleex','agee':22}
f['names'] = names
f['info'] = info
f.close()

解决办法,将open()里的文件后缀名去掉,因为shelve存储文件后缀名为.bak .dir,open()里的文件名不需要提供扩展名,系统会自动
帮你创建后缀名为.bak .dir格式的存储文件.
原文地址:https://www.cnblogs.com/zhoudabing/p/10404366.html