Python通讯簿
这两天在学习python语言,也学着写了个通讯簿,练习入门下!
功能包括以下:
1、增加一条记录
2、删除一条记录
3、修改一条记录
4、查询一条记录
5、显示整个通讯簿
6、帮助提示
7、版本显示
8、退出等
首先建立一个Person类,即Person.py文件,用来保存联系人记录:
class Person:
def __init__(self, name, email, phone):
self.name = name
self.email = email
self.phone = phone
接下来是个addressBook.py文件,用以实现上面提到的功能,这里用了存储器,将对象保存在文件中来实现数据存储。
import cPickle as p
from Person import Person
filename = 'addressBook.data'
while True:
order = raw_input('/////////////////////////////////////\nEnter your order:')
#add
if order == 'add':
addName = raw_input('Enter name:')
f = file(filename)
dic = p.load(f)
if dic.has_key(addName) == False:
dic[addName] = Person(addName, raw_input('Enter email:'), raw_input('Enter phone:'))
f = file(filename, 'w')
p.dump(dic, f)
f.close()
#delete
elif order == 'del':
delName = raw_input('Enter name who you will delete:')
f = file(filename)
dic = p.load(f)
if dic.has_key(delName):
del dic[delName]
f = file(filename, 'w')
p.dump(dic, f)
f.close()
#modify
elif order == 'mod':
modName = raw_input('Enter name who you will modify:')
f = file(filename)
dic = p.load(f)
if dic.has_key(modName):
dic[modName] = Person(modName, raw_input('Enter email:'), raw_input('Enter phone:'))
f = file(filename, 'w')
p.dump(dic, f)
f.close()
#search
elif order == 'search':
schName = raw_input('Enter name who you will search:')
f = file(filename)
dic = p.load(f)
if dic.has_key(schName):
psch = dic[schName]
print psch.name
print psch.email
相关文档:
Python http://www.python.org/download/ wxPython http://www.wxpython.org/download.php#binaries Vpython http://vpython.org/contents/download_windows.html Matplotlib http://sourceforge.net/projects/matplotlib/files/matplotlib/ PyGlet http://www.pyglet.org/download.html PyGame http://www.pyga ......
转自:
http://hi.baidu.com/feng2211/blog/item/8b86b6d9816a3f2710df9b79.html
和
http://i.19830102.com/archives/164
Python 版本:2.6
下载地址:http://www.python.org/download/releases/2.6.1/
下载msi文件并安装
MySQLdb版本: MySQL-python-1.2.2.win32-py2.6.exe
下载地址:http://home.netimperia.com/ ......
Memcached
是danga.com(运营LiveJournal的技术团队)开发的一套分布式内存对象缓存系统,用于在动态系统中减少数据库负载,提升性能。
网上有很多讲到Memcached For Linux的安装教程,但是Memcached For Win32 and Python的就甚少,偶尔google找到一篇
比较相近的英文教程,觉得 ......