[Python] Little practice __ Create your own command-line Address Book program

Source: Internet
Author: User

Create your own command-line address book program.

In this app, you can add, edit, delete, and search your contacts (friends, family, colleagues, etc.) and their information (such as e-mail addresses and/or phone numbers).

These details should be saved for later extraction.

Python version 3.4.3

1 #Create your own command-line address book program. In this program,2 #you can add, edit, delete, and search your contacts (friends, family, colleagues, and so on).3 #and their information (such as e-mail addresses and/or phone numbers). 4 #These details should be saved for later extraction. 5 #python version 3.4.36 ImportPickle as P7 ImportSYS8 ImportOS9 Tenfilename ='Phonebook.data' One  A #create a class that represents a person's information - classMember: -     def __init__(self,name,mail,phone): theSelf.name =name -Self.mail =Mail -Self.phone =Phone -  + #remove the object from the file and return - defreadbypickle (filename): +f = open (filename,'RB') AInfos =p.load (f) at f.close () -     returninfos -  - #writing an object to a file - defWritebypickle (infos,filename): -f = open (filename,'WB') in p.dump (infos,f) - f.close () to  + defScanall (): -Infos =readbypickle (filename) the      forName,infoinchInfos.items (): *         Print(Name,'\ t', info) $     delinfosPanax Notoginseng     #Infos Here is the object, run out and remember to clear out -  the #key in someone,receive the info + defsearch (): AInfos =readbypickle (filename) theperson = input ('Please enter the name of you search:') +     ifPersoninchinfos: -         Print('Result:', Infos[person]) $     Else: $         Print('No data!') -     delinfos -  the defupdate (): -info = input ('Please enter your updating info like:someone,[email protected],123: \ n')WuyiInfo_1 = Info.split (',') thetemp = Member (info_1[0],info_1[1],info_1[2]) -Infos =readbypickle (filename) WuInfos[temp.name] = Temp.mail +','+Temp.phone - Writebypickle (infos,filename) About     delinfos $  - defDelete (): -Infos =readbypickle (filename) -info = input ('Please enter the name of the want to delete:') A     Try: +         delInfos[info] the     except: -         Print('Delete failed,please Check your input.') $     finally: the         Print(infos) the Writebypickle (infos,filename) the         delinfos the  - defMain (): in      whileTrue: theCommand = input ('\n==========menu==========\n1 scan\n2 search\n3 update\n4 delete\n5 exit\n') the         ifCommand = ='1': About Scanall () the         elifCommand = ='2': the Search () the         elifCommand = ='3': + Update () -         elifCommand = ='4': the Delete ()Bayi         Else: the sys.exit () the Print('Versioninfo:', Sys.version) - if(os.path.exists (filename)): - Main () the Else: theInfos = {'Rebecah':'[Email protected],12345'} the Writebypickle (infos,filename) theMain ()

[Python] Little practice __ Create your own command-line Address Book program

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.