#!/usr/bin/env python#coding=utf-8# Phone Book management, you can add, delete, modify, query user information import Cpickle as P class Telephone:def __init__ (self): "Construction Method" Def addpeople (Self,name,email,telephone): "" "Add User" "" Teledict = Self.getdictda Ta () if teledict:infolist = [Name,email,telephone] teledict[name] = infolist Self.writefile (teledict) else:teledict = {} infolist = [Name,email,telephone] Te Ledict[name] = infolist Self.writefile (teledict) def delpeople (self,name): " "" Delete User "" "Teledict = Self.getdictdata () If name in Teledict.keys (): Del Teledict[name] Self.writefile (teledict) else:print name, ' isn't in Dict ' Def editpeople (Self,name,emial,telep Hone): "" "" "" "" "" "" Teledict = Self.getdictdata () If name in Teledict.keys (): Infolist = [n Ame,email,telephone] Teledict[name] = infolist self.writefile (teledict) print name+ ' edit Success ' Els E:print name, ' isn't in Dict ' Def getPeople (self,name): "" "Get User Information" "" Teledict = Self.getdictdata () If teledict:if name in Teledict.keys (): people = Teledict[name] Print people else:print name, ' isn't in dict ' else:print ' people is empty ' def writefile (self, Dictdata): "" "" "Write File" "" F = [File (' Dict.data ', ' W ') P.dump (dictdata,f) f.close () def getdictdata (self): "" "Get File Contents" "" FileName = ' dict.d ATA ' try:f = file (fileName) teledict = P.load (f) return teledict except: print ' Open file error ' # hint message def notice (): print "Please enter 1-get people 2-add people 3-edit pelole 4- Del people 5-get all PEOple 0-break "if __name__ = =" __main__ ": while (True): notice () userinput = Int (raw_input ()) People = telephone () if userinput = = 1:name = Raw_input ("Please enter user name:") PEO Ple.getpeople (name) elif Userinput = = 2:name = Raw_input ("Enter name:") email = raw_input ("E Nter emai: ") telephone = raw_input (" Enter Telephone: ") people.addpeople (Name,email,telephone) elif Userinput = = 3:name = Raw_input ("Enter name:") email = raw_input ("Enter Emai:") te Lephone = Raw_input ("Enter Telephone:") people.editpeople (name,email,telephone) elif Userinput = = 4: Name = Raw_input ("Enter del people Name:") people.delpeople (name) elif Userinput = = 5: Allpeople = People.getdictdata () if Allpeople:for key in Allpeople:print Key,allpeople[key] Else:print ' There is no people ' elif userinput = 0:break Else: print ' You select number is wrong ' raw_input (' press ENTER ')