#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': }
[, , , , ]

dbm.error: need 'c' or 'n' flag to open new db的更多相关文章

  1. 初学tensorflow遇到的Error——UnrecognizedFlagError: Unknown command line flag 'f'

    最近在学习<tensorflow实战>时需要下载cifar10数据集,在cifar10目录下用到命令: import cifar10,cifar10_inputcifar10.maybe_ ...

  2. iOS ERROR: unable to get the receiver data from the DB 解决方式

    这个错误通常发生在iOS7其中,可能是缓存的导致的问题. 解决步骤: 右击Finder,选择 Go to Folder 复制上:"~/Library/Application Support/ ...

  3. python之shelve模块详解

    一.定义 Shelve是对象持久化保存方法,将对象保存到文件里面,缺省(即默认)的数据存储文件是二进制的. 二.用途 可以作为一个简单的数据存储方案. 三.用法 使用时,只需要使用open函数获取一个 ...

  4. 12 python json&pickle&shelve模块

      1.什么叫序列化 序列化是指把内存里的数据类型转变成字符串,以使其能存储到硬盘或通过网络传输到远程,因为硬盘或网络传输时只能接受bytes(字节) 2.用于序列化的两个模块,json和pickle ...

  5. time、random以及序列化模块

    一. time模块 在Python中,通常有这几种方式来表示时间: 时间戳(timestamp):通常来说,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量.我们运行“type( ...

  6. Go内置库模块 flag

    import "flag" flag包实现了命令行参数的解析.每个参数认为一条记录,根据实际进行定义,到一个set集合.每条都有各自的状态参数. 在使用flag时正常流程: 1.  ...

  7. golang flag

    本文主要对golang环境下命令行的解析进行了相关的总结.命令行在C下有getopt等函数, 在golang下提供了更为方便的处理方法. 1.命令行参数获取:命令行获得可通过os.Args参数, Ar ...

  8. Go基础篇【第6篇】: 内置库模块 flag

    import "flag" flag包实现了命令行参数的解析.每个参数认为一条记录,根据实际进行定义,到一个set集合.每条都有各自的状态参数. 在使用flag时正常流程: 1.  ...

  9. [转]MySQL: Starting MySQL….. ERROR! The server quit without updating PID file

    转自: http://icesquare.com/wordpress/mysql-starting-mysql-error-the-server-quit-without-updating-pid-f ...

随机推荐

  1. SSM的理解

    SSM(Spring+SpringMVC+MyBatis)框架集由Spring.SpringMVC.MyBatis三个开源框架整合而成,常作为数据源较简单的web项目的框架.其中spring是一个轻量 ...

  2. 为什么List.add()所增加的数据都是一样的

    1. 先上代码: List<Person> list = new ArrayList<>(); Person p = new Person(); try { Class.for ...

  3. .net下安装 ZooKeeper.Net

    PM> Install-Package ZooKeeper.Net正在尝试解析依赖项“log4net (≥ 1.2.10)”.正在安装“log4net 1.2.10”.已成功安装“log4net ...

  4. python简说(二十二)写日志

    分四个级别 import nnloglog = nnlog.Logger('book_server.log') log.debug('xxx值是什么')log.info('调用了什么xxx')log. ...

  5. poj 2096 Collecting Bugs - 概率与期望 - 动态规划

    Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other material stu ...

  6. fatal: unable to access 'https://github.com/open-falcon/falcon-plus.git/': Peer reports incompatible or unsupported protocol version

    git通过git clone下载github上的资源到机器上,结果出现如题所示的错误. [root@server data]# git clone https://github.com/pingcap ...

  7. python脚本解析json文件

    python脚本解析json文件 没写完.但是有效果.初次尝试,写的比较不简洁... 比较烦的地方在于: 1,中文编码: pSpecs.decode('raw_unicode_escape') 2,花 ...

  8. 使用SimpleDateFormat时的日期和时间模式

    日期和时间模式 日期和时间格式由日期和时间模式 字符串指定.在日期和时间模式字符串中,未加引号的字母 ‘A’ 到’Z’ 和’a’ 到’z’ 被解释为模式字母,用来表示日期或时间字符串元素.文本可以使用 ...

  9. ubuntu18.04无法安装libesd0-dev【学习笔记】

    执行如下命令安装: sudo apt-get install libesd0-dev 却报了这个错误: 解决办法: sudo vim /etc/apt/sources.list //在行尾添加如下两行 ...

  10. 网络存储结构简明分析—DAS、NAS和SAN 三者区别

    存储的总体分类     主流存储结构   网络存储结构大致分为三种:直连式存储(DAS:Direct Attached Storage).存储区域网络(SAN:Storage Area Network ...