python使用CSV实现电话本
来源:互联网 发布:生产型进销存软件 编辑:程序博客网 时间:2024/05/29 15:59
开始学习Python,看了一道程序 http://www.oschina.net/code/snippet_230735_8468, 在此基础上修改了一下,
#!/bin/python# coding:utf-8import timeimport csvclass TelBook: def __init__(self, filename): self._filename = filename """print title into file""" csvfile = file(self._filename, "wb") writer = csv.writer(csvfile) title = ["NAME", "TEL", "TIME"] writer.writerow(title) csvfile.close() def addPerson(self): """Add a new person information""" person = raw_input("Enter the person\'s name:") tel = raw_input("Enter the person\'s tel:") update = time.strftime("%Y-%m-%d %H:%m:%S") writer = csv.writer(file(self._filename, "ab")) writer.writerow([person, tel, update]) def findPerson(self, personname): """find a person's information and print to terminal""" csvfile = file(self._filename, "rb") reader = csv.reader(csvfile) flag = False for person in reader: if person[0] == personname: print person flag = True break if not flag: print "Not find information of person with " + personname csvfile.close() #TODO:Delete person informationdef prompt(): print "a/A : add a person tel information;" print "f/F : find a person tel information;" print "q/Q : quit."def mainLoop(): obj = TelBook("telbook.csv") flag = True while flag: choice = raw_input("Pls input your choice?(h for help)") if choice == 'a' or choice == 'A': obj.addPerson() elif choice == 'f' or choice == 'F': name = raw_input("Input the person\'s name you want to find:") obj.findPerson(name) elif choice == 'h' or choice == 'H': prompt() elif choice == 'q' or choice == 'Q': print "Thank you! Bye-bye!" flag = False else: print "Your input is invalid!"if __name__ == "__main__": print "Welcome to TelBook!" prompt() mainLoop()
- python使用CSV实现电话本
- python csv模块使用
- python csv模块使用
- python使用csv模块读写csv文件
- python实现csv转josn
- python shell电话本
- python练习题 0 电话本
- 【Python】 csv模块的使用
- python csv模块的使用
- [python]csv格式文件的使用
- python CSV模块使用笔记
- python csv模块使用实例
- 【Python】 csv模块的使用
- 使用python处理csv文件
- Python csv模块的使用
- Python csv模块的使用
- 【Python】 csv模块的使用
- python csv的使用整理
- 关于setjmp longjmp的使用
- Structed Exception Handler 学习总结(二)
- 《UNIX环境高级编程》笔记--打开流
- 计算机的性能指标
- 出口程序的查找和开发(CMOD和SMOD)
- python使用CSV实现电话本
- Android之复选按钮、单选按钮、开关按钮
- 黑马程序员-我的摘录-值类型和引用类型的再次了解
- query的查看和寻找
- oracle中表与序列的关联
- 笔试题7-数据库(ORACLE)
- Structed Exception Handler 学习总结(三)
- GridView控件中添加CheckBox控件,并且实现选择、全选和反选
- 2014找工作阶段性总结