dbm.error: need 'c' or 'n' flag to open new db

#coding=utf-8
import shelve
with shelve.open("shelve.ini","w") as f:
f["k1"] = test_list
f["k2"] = test_dict
f["k3"] = s with shelve.open("shelve.ini","r") as f:
print(f["k3"])
print(f["k2"])
print(f["k1"])

报错

    raise error[]("need 'c' or 'n' flag to open new db")
dbm.error: need 'c' or 'n' flag to open new db

改为如下,加入c参数:

#coding=utf-
import shelve
test_list=[,,,,]
test_dict={"aaa":,"bbb":}
s="xiaoming"
with shelve.open("shelve.ini","wc") as f:
f["k1"] = test_list
f["k2"] = test_dict
f["k3"] = s with shelve.open("shelve.ini","rc") as k:
print(k["k3"])
print(k["k2"])
print(k["k1"])

输出

xiaoming
{'aaa': , 'bbb': }
[, , , , ]
上一篇:django的admin后台注册model并显示


下一篇:GDI+ 学习记录(26): 显示图像 - Image