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()