#!/usr/bin/python
#Filename:phone_list.py
#this file aims to finish a phone number list
#and it has the func like add delete query and read
import cPickle as p
file_list = '/home/denglaoda/python/peoplePhone.data'
class friend:
def __init__(self,email,addr,number,name):
self.email = email
self.addr = addr
self.number = number
self.name = name
list = {}
a = friend('[email protected]',"sjtu",'15021973910',"denglaoda")
print a.email
list['denglaoda'] = a
print list["denglaoda"].email
def AddPerson(a,b,c,d):
f = open(file_list,'r')
list = p.load(f)
f.close()
print f
f = open(file_list,'w')
temp = friend(a,b,c,d)
list[temp.name] = temp
p.dump(list,f)
f.close()
print "people added:\n",temp.name,temp.number,temp.email,temp.addr
#AddPerson('[email protected]','sjtu','13774398956','zhoukan')
def read():
fo = open(file_list,'r')
o = p.load(fo)
print 'name number email addr\n'
for i in o:
print
print o[i].name,o[i].number,o[i].email,o[i].addr
fo.close()
del o
def add():
'''please input the information if finish please input "over"'''
input_name = raw_input('enter the name:')
if input_name == 'over':
read()
return
input_addr = raw_input('enter the addr:')
input_number = raw_input('enter the number:')
input_email = raw_input('enter the email:')
AddPerson(input_email,input_addr,input_number,input_name);
def query():
a = raw_input('inpuy name you want to query---->')
if a == 'over':
return
fo = open(file_list,'r')
o = p.load(fo)
if o.get(a):
print o[a].name,o[a].number,o[a].email,o[a].addr
else:
print"sorry no this member!!!\n"
fo.close()
del o
def delete():
a = raw_input('which do you want to delete-->')
if a == 'over':
return
if a == 'zhoukan':
print'sorry the owner could not be deleted'
return
fo = open(file_list,'r')
o = p.load(fo)
fo.close()
del o[a]
fo = open(file_list,'w')
p.dump(o,fo)
fo.close()
read()
while True:
print '''yes, you can query,add,read or delete to this people list
'''
s = raw_input('let me know what you want to do$$$')
if s == 'quit':
break
if s == 'query':
query()
if s == 'add':
add()
if s == 'read':
read()
if s == 'delete':
delete()
if s == 'zhoukan':
print
print ' I love you!!! '
# print '\n\nI am now reading\n\n'
#read()
|