Where is the Python address book and foxmail address book?

Source: Internet
Author: User

Where is the Python address book and foxmail address book?

1 #! /Usr/bin/python 2 # coding = UTF-8 3 # FileName: address. py 4 # Python Address Book 5 import cPickle as p; 6 import OS; 7 import sys; 8 class Address: 9 '''python Address Book ''' 10 # constructor 11 def _ init _ (self): 12 self. dataFileName = 'address. data'; 13 self. dataPath = OS. getcwd () + OS. sep; 14 handle = file (self. dataPath + self. dataFileName, 'w'); 15 try: 16 self. peopleList = p. load (handle); 17 bytes T: 18 print '% s is emp Ty. initializing... '% (self. dataFileName); 19 self. peopleList ={}; 20 handle. close (); 21 ### 22 # Add an address book 23 # @ access public 24 # @ author zhaoyingnan 2016-03-01 10:10:46 25 # @ param string username 26 # @ param string marks remarks 27 # @ param mobile phone number 28 # @ param string email address 29 # @ return mix 30 # @ note 31 ### 32 def addPeople (self, username, marks, mobile, email): 33''' add an address book ''' 34 I F self. peopleList. get (username, 404) = 404: 35 newPeople = {'username': username, 'mark': marks, 'mobile': mobile, 'email ': email }; 36 self. peopleList [username] = newPeople; 37 else: 38 'already exist. '; 39 40 ### 41 # delete an address book 42 # @ access public 43 # @ author zhaoyingnan # @ param string username 45 # @ return mix 46 # @ note 47 ##48 def delPeople (self, username): 49 if self. pe OpleList. get (username, 404) == 404: 50 print '% s non-existent. '% (username); 51 else: 52 del self. peopleList [username]; 53 print 'OK. '; 54 55 ### 56 # modify an address book 57 # @ access public 58 # @ author zhaoyingnan # @ param string username 60 # @ param string index (username/marks /mobile/email) 61 # @ param string value index value 62 # @ return mix 63 # @ note 64 ### 65 def updatePeople (self, Username, index, value): 66 if self. peopleList. get (username, 404) == 404: 67 print '% s non-existent. '% (username); 68 # sys. exit ('% s non-existent! '% (Username); 69 else: 70 self. peopleList [username] [index] = value; 71 72 ### 73 # retrieve list 74 # @ access public 75 # @ author zhaoyingnan 2016-03-01 76 # @ return string 77 # @ note 78 ### 79 def getPeople (self): 80 if len (self. peopleList)> 0: 81 for username, arList in self. peopleList. items (): 82 print '-----------------------------'; 83 print '\ t % s \ t' % (username); 84 for key, value in arList. items (): 85 print '% s \ t % s' % (key, value); 86 print' ------------------------------- '; 87 else: 88 print' % s is empty. '% (self. dataFileName); 89 90 # store the address play in the file 91 def _ del _ (self): 92 handle = file (self. dataPath + self. dataFileName, 'w'); 93 p. dump (self. peopleList, handle); 94 handle. close (); 95 96 97 address = Address (); 98 address. addPeople ('lil', 'lihongbin', 18911937250, '2017 @ qq.com '); 99 address. addPeople ('zhaoyn', 'zhaoyingnan ', 15932279586, '2017 @ qq.com'); 409586363 address. addPeople ('Mr. zhu ', 'zhuxiaohuan', 13303028786, '2017 @ qq.com '); 12802390939 address. delPeople ('Mr. zhu '); 102 address. updatePeople ('Liu ', 'mark', 'liuqing'); 103 address. updatePeople ('zhao', 'mark', 'Mr. zhao '); 104 address. getPeople ();

 

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.