Core code:
Copy Code code as follows:
#!/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 ' 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 '
Class Alterperson:
def __init__ (self,name,email):
Self.name=name
Self.email=email
def alterbook (self):
ab=frilist
Ab[sname]=email
dumpfile (AB)
del AB
print ' succlessful update! '
print ' ' \
This is prints files to the standard output.
Any number of the files can be specified.
Options include:
[1]: Search your friend ' s email from Friendsbook
[2]: Add your friend ' s email to Firendsbook
[3]: del your friend ' s email from Firnedsbook
[4]: Alter your friend ' s email from Friendsbook
[5]: All friends List
[6]: Exit the program
'''
Num=raw_input (' Press the number [1,2,3,4,5]--> ')
if (num== ' 1 '):
Sname=raw_input (' Enter the name--> ')
If sname in Frilist:
P=person (sname)
P.saysome ()
Else
print ' Not in it '
Elif (num== ' 2 '):
Sname=raw_input (' Enter the name--> ')
Email=raw_input (' Enter the email--> ')
Pa=addperson (Sname,email)
Pa.addbook ()
#p =person (sname)
#p. Saysome ()
Print Frilist
Elif (num== ' 3 '):
Sname=raw_input (' Enter the name--> ')
Pa=delperson (sname)
Pa.delbook ()
Elif (num== ' 4 '):
Sname=raw_input (' Enter the name--> ')
If sname in Frilist:
Email=raw_input (' Enter the email--> ')
P=alterperson (Sname,email)
P.alterbook ()
Else
print ' Not in it '
Elif (num== ' 5 '):
Print Frilist
Elif (num== ' 6 '):
Print "bye!"
Else
Print "Please input to the right number"
Note: This is I write the first python, there are many deficiencies, later improved