还没有写完准备弡上cpickle 还有字典
#!/usr/bin/python
#Filename: cpickle.py import cPickle as p
import os shoplistfile="shoplist.data"
storedlist={} def menu():
running=True
try:
while running:
try:
f=file(shoplistfile)
storedlist=p.load(f)
command=raw_input("Please input command: ")
if command=="help":
help()
elif command=="add":
add(storedlist)
elif command=="delete":
delete(storedlist)
elif command=="update":
update(storedlist)
elif command=="select":
select(storedlist)
elif command=="quit":
running=False
elif command=='show':
show(storedlist)
else:
print "ERROR, please input help!"
finally:
f.close()
else:
print "Done"
except EOFError:
print "QUIT"
except KeyboardInterrupt:
print "Q"
finally:
print "DONE" def show(storedlist):
print '-'*40
for (k,v) in storedlist.items():
print '%s \t'%k,v
print '-'*40 def add(storedlist):
try:
username=raw_input("Please input add username:")
# print storedlist
# print username
if(storedlist.has_key(username)):
print "Username Exist!!"
return 0
emailbox=raw_input("Please input add email:")
storedlist[username]=emailbox
except:
print "err add"
finally:
write(storedlist) def select(storedlist):
try:
username=raw_input("Please input select username:")
if storedlist.has_key(username):
print storedlist[username]
else:
print 'Username not find!!'
return 0
except:
print "err select"
finally:
write(storedlist) def delete(storedlist):
try:
username=raw_input("Please input delete username:")
if storedlist.has_key(username):
print storedlist[username]
else:
print 'Username not find!!'
return 0
storedlist.pop(username)
except:
print "err delete"
finally:
write(storedlist) def update(storedlist):
try:
#not key ?
username=raw_input("Please input update username:")
if storedlist.has_key(username):
print storedlist[username]
else:
print 'Username not find!!'
return 0
emailbox=raw_input("Please input update email:")
storedlist[username]=emailbox
except:
print "err update"
finally:
write(storedlist) def write(stored):
f=file(shoplistfile,'w')
p.dump(stored,f)
f.close() def index():
if os.path.exists(shoplistfile):
menu()
else:
print 'Contacts not find!'
print 'Create Contacts...'
create_con() def create_con():
shoplist={}
try:
f=file(shoplistfile,'w')
p.dump(shoplist,f)
except IOError:
print 'find not file!!'
finally:
f.close()
menu() def help():
"""
------------------------
==>>help
==>>add < username email >
==>>delete < username >
==>>update < username newemail >
==>>select < username >
==>>quit
------------------------"""
print help.__doc__ if __name__=='__main__':
index()
练习字典,看简明的python后面有一个练习,根据cPickle 写一个通讯录,恶心下自己!
还没有写完准备弡上cpickle 还有字典的更多相关文章
- 前端性能测试工具 : dynaTrace Ajax (还没写完)
今天开始写这个工具, #什么是dynaTrace Ajax? 随着 jQuery.Dojo.YUI 等框架的兴起让构建 Web2.0 应用更加容易,但随之带来的定位等应用问题也越来越难,尤其是与性能相 ...
- XObject.java 对象还没写完,希望电脑不会丢失。坏笑,早点见。
/*面向对象强调的是对象, 面向过程强调的是功能行为,打开行为,关闭行为,执行行为,把多个行为封装成对象执行更强大的功能就是面向对象,是把多个函数, 多 个行为封装在一起,单一的函数执行对象的功能太困 ...
- 【creo】CREO5.0+VS2019配置(还没写完)
欢迎大家一起学习使用c++对CREO5.0二次开发. 第1步,建立开发目录:在E盘(或者其他盘)新建creo_cpp文件夹,文件夹中新建ABC_TOOLS用来存放我们开发的工具,CODE文件夹存放开发 ...
- HDU 4640 状态压缩DP 未写完
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4640 解题思路: 首先用一个简单的2^n*n的dp可以求出一个人访问一个给定状态的最小花费,因为这i个 ...
- webuploader 跨域上传demo(还没有写记录一下)
webuploader 跨域上传demo(还没有写记录一下)
- 写完代码就去吃饺子|The 10th Henan Polytechnic University Programming Contest
河南理工大学第十届校赛 很久没有组队打比赛了,好吧应该说很久没有写题了, 三个人一起玩果然比一个人玩有趣多了... 前100分钟过了4题,中途挂机100分钟也不知道什么原因,可能是因为到饭点太饿了?, ...
- 缓存服务,还未创建完缓存时, 需要更改图层名称、服务名称、数据源位置、mxd名称等
缓存服务,还未创建完缓存时, 需要更改图层名称.服务名称.数据源位置.mxd名称等.已经创建好的缓存还可以再用吗? 测试后可以, 注意:新服务相对旧服务,符号样式没有改变,切片方案没有变化. 测试步骤 ...
- 用putty玩linux的时候由于以前用window 习惯写完东西按一下ctrl+s 保存
问题描述:用putty玩linux的时候由于以前用window 习惯写完东西按一下ctrl+s 保存,但是在putty一按下就不能再输入了.后来查找到:ctrl+s 是putty的一个命令大概是这样子 ...
- 不写完不让回家的JQuery的事件与动画
在这看不见太阳的小黑屋里,苦逼的一天又开始了 好了闲话我也就不扯了,接下来我就来说说我对jQuery事件和动画的理解吧!!! 还是得再扯两句,我们敬爱的,Y老师讲完了,jQuery事件和动画,对着我们 ...
随机推荐
- 解决C3P0在Linux下Failed to get local InetAddress for VMID问题
解决C3P0在Linux下Failed to get local InetAddress for VMID问题 FailedtogetlocalInetAddressforVMID.Thisisunl ...
- 跨年操作--new Date()
//时间在2017/12/31 17:00 --- 2018/1/1 06:00区间,提示用户无法操作公告. //time.js (function(){ var date = new Date(); ...
- 联想电脑 Wifi开关开不了
"VirtualBox Host-Only Network" 没有有效的IP配置 未修复 自己电脑显示 控制面板>网络和Internet>网络连接 VirtualBo ...
- mybatis in查询 传入string
<select id="selectChoosenumberdetailNumber" > SELECT number FROM choosenumberdetail ...
- asp.net 修改AD账号信息
public void ADInfoEdit(ADUser adu) { try { DirectoryEntry dADM; DirectoryEntry objectuser = null; dA ...
- 对程序"加料"
我们如果想对已有的程序做手脚,就要在原有的结构中添加自己的代码,这样当用户在打开这个做过手脚的程序时就会自动运行其中我们加进去的代码,至于这些代码能做什么,你懂得.这个实验的目的是在一个EXE可执行文 ...
- BASE64Encoder/BASE64Decoder(转)
eclipse中解除jdk的访问限制(以BASE64Encoder/BASE64Decoder为例) 解除访问限制前: 所以需要添加一个访问许可,步骤如下: 1.选择所在项目,右击鼠标选择Build ...
- Failed to start LSB: Bring up/down networking 问题
Failed to start LSB: Bring up/down networking 问题 1.执行 service network restart 出现以下错误 Restarting ne ...
- 原生js实现一个简单的轮播图
想锻炼一下自己的原生js能力可以从写一个轮播图开始,轮播图的运用想必大家都知道吧,好了废话不多说,开始记笔记了,一些需要注意的点,我都在代码中标注了 首先是构造html: <div id=&qu ...
- mysql 5.7 基于GTID 主从同步的1236故障处理(其它事务故障等同)
登录从库 stop slave; 查看执行事务 show slave status\G Retrieved_Gtid_Set: Executed_Gtid_Set: ee3bdb44-f6a1-11 ...