代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Python
】
电话本管理例子
作者:
php码农一个
/ 发布于
2015/1/12
/
745
电话本管理,可以进行添加,删除,修改,查询用户
#!/usr/bin/env python #coding=utf-8 #电话本管理,可以进行添加,删除,修改,查询用户信息 import cPickle as p class Telephone: def __init__(self): '''构造方法 ''' def addPeople(self,name,email,telephone): """添加用户""" teleDict = self.getDictData() if teleDict: infoList = [name,email,telephone] teleDict[name] = infoList self.writefile(teleDict) else: teleDict = {} infoList = [name,email,telephone] teleDict[name] = infoList self.writefile(teleDict) def delPeople(self,name): """删除用户""" teleDict = self.getDictData() if name in teleDict.keys(): del teleDict[name] self.writefile(teleDict) else: print name,'is not in dict' def editPeople(self,name,emial,telephone): """ 修改信息""" teleDict = self.getDictData() if name in teleDict.keys(): infoList = [name,email,telephone] teleDict[name] = infoList self.writefile(teleDict) print name+'edit success' else: print name,'is not in dict' def getPeople(self,name): """获取用户信息""" teleDict = self.getDictData() if teleDict: if name in teleDict.keys(): people = teleDict[name] print people else: print name,'is not in dict' else: print 'people is empty' def writefile(self, dictData): """ 写入文件""" f = file('dict.data','w') p.dump(dictData,f) f.close() def getDictData(self): """ 获取文件内容""" fileName = 'dict.data' try: f = file(fileName) teleDict = p.load(f) return teleDict except: print 'open file error' # 提示 信息 def notice(): print "please enter 1-get people 2-add people 3-edit pelole 4-del people 5-get all people 0-break" if __name__ == "__main__": while(True): notice() userInput = int(raw_input()) people = Telephone() if userInput == 1: name = raw_input("please enter user name:") people.getPeople(name) elif userInput == 2: name = raw_input("enter name:") email = raw_input("enter emai:") telephone = raw_input("enter telephone:") people.addPeople(name,email,telephone) elif userInput == 3: name = raw_input("enter name:") email = raw_input("enter emai:") telephone = raw_input("enter telephone:") people.editPeople(name,email,telephone) elif userInput == 4: name = raw_input("enter del people name:") people.delPeople(name) elif userInput == 5: allpeople = people.getDictData() if allpeople: for key in allpeople: print key,allpeople[key] else: print 'there is no people' elif userInput == 0: break else: print 'you select number is wrong' raw_input('press enter')
试试其它关键字
电话本管理
同语言下
.
比较两个图片的相似度
.
过urllib2获取带有中文参数的url内容
.
不下载获取远程图片的宽度和高度及文件大小
.
通过qrcode库生成二维码
.
通过httplib发送GET和POST请求
.
Django下解决小文件下载
.
遍历windows的所有窗口并输出窗口标题
.
根据窗口标题调用窗口
.
python 抓取搜狗指定公众号
.
pandas读取指定列
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
php码农一个
贡献的其它代码
(
1
)
.
电话本管理例子
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3