码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2019-02-17 23:47:27      阅读:295      评论:0      收藏:0      [点我收藏+]

标签:erro   raise   输出   color   error:   ror   bsp   bbb   import   

 

 

#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[0]("need ‘c‘ or ‘n‘ flag to open new db")
dbm.error: need c or n flag to open new db

 

改为如下,加入c参数:

#coding=utf-8
import shelve
test_list=[1,2,3,4,5]
test_dict={"aaa":23,"bbb":33}
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: 23, bbb: 33}
[1, 2, 3, 4, 5]

 

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

标签:erro   raise   输出   color   error:   ror   bsp   bbb   import   

原文地址:https://www.cnblogs.com/sea-stream/p/10393264.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!