Python address book

Source: Internet
Author: User

Create your own command lineAddress bookProgram. In this program, you can add, modify, delete, and search for your contacts (friends, family members, and colleagues) and their information (such as email addresses and/or phone numbers)

#!/usr/bin/python# Filename : var.py  import cPickle as pimport osimport sysfilename = 'contacts.data'class member:def __init__(self, name, address, tel):self.name = nameself.address = addressself.tel = teldef select():f = file(filename)conlist = p.load(f)print conlists = raw_input('Please enter the name which you want to select: ')if s in conlist:print s, ':', conlist[s]else:print "Don't find!"def update():s = raw_input('Please input similar to hehe,haha@.cn,10086: ')s1 = s.split(',')temp = member(s1[0], s1[1], s1[2])f = file(filename)conlist = p.load(f)conlist[temp.name] = temp.address+','+temp.telf = file(filename, 'w')p.dump(conlist, f)f.close()del conlist#print againf = file(filename)conlist = p.load(f)for name, other in conlist.items():print 'name is: %s, other is: %s' % (name, other)def delete():f = file(filename)conlist = p.load(f)print conlistd = raw_input("Please input the person's name you want to delete: ")del conlist[d]print conlistf = file(filename, 'w')p.dump(conlist, f)f.close()del conlistdef main():while True:choice = raw_input('1.select\n2.update\n3.delete\n4.exit\n')if choice == '1':select()elif choice == '2':update()elif choice == '3':delete()elif choice == '4':sys.exit()else:print "Don't have this option, Please try again!"if os.path.exists('contacts.data'):main()else:f = file('contacts.data', 'w')conlist = {'hehe':'haha@cn,10086'}p.dump(conlist, f)f.close()del conlistmain()



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.