核心代码:
代码如下:
#!/usr/bin/python
#Filename:friendbook.py
import cPickle as p
import sys
import time
import os
ab={'Xdex':'cneds@fnedf.com',
'Laexly':'fev@fe.com',
'Fukc':'fexok@ver.com',
'Stifu':'stif@qq.com'
}
def Dumpfile(list):
f=file(friendab,'w')
p.dump(list,f)
f.close()
if os.path.isfile('friendab.data'):
friendab='friendab.data'
else:
os.touch('friendab.data')
Dumpfile(ab)
del ab
f=file(friendab)
frilist=p.load(f)
class Person:
def __init__(self,name):
self.name=name
def saysome(self):
print 'The friend %s,his E-mail is %s '%(sname,frilist[sname])
class addPerson:
def __init__(self,name,email):
self.name=name
self.email=email
def addbook(self):
ab=frilist
ab[sname]=email
Dumpfile(ab)
del ab
print 'Succlessful!'
class delPerson:
def __init__(self,name):
self.name=name
def delbook(self):
ab=frilist
ab.pop(sname)
Dumpfile(ab)
del ab
print 'Success DEL'
新闻热点
疑难解答