Python program description

Source: Internet
Author: User

Python is free and open-source, and can be transplanted to multiple operating systems. As long as you do not need to use features dependent on specific operating systems, Python programs can run on various platforms without modification, having mastered the Python program makes programming easier and easier.

As the name implies, PILPython Imaging Library is built on Python, So I downloaded Python2.6 from the day before yesterday and read the Python Concise Manual. At the end of this manual, the author suggests that beginners create a command line Address Book Program.

In this program, you can add, modify, delete, and search for your contacts, friends, family, and colleagues) and their information such as email addresses and/or phone numbers ). The details should be saved for future extraction. Use a Python program.

After several hours of hard work, the program code is as follows: By the way, Python is really better to use, but it is much easier than learning VC/MFC at the beginning, of course, it may be partly because you have already experienced c ++)

 
  1. # MyFirstIntegratedPythonProgram
  2. Import cPickle as P
  3. Class notebook:
  4. Dictnote= {}
  5. Def _ init _ (self ):
  6. Notebook. dictnote= {'Randy ': '123 ',
  7. 'Jackson ': '123 ',
  8. 'Mary ': '000000 '}
  9. F=File('StoreFile.txt ', 'A ')
  10. P. dump (notebook. dictnote, f)
  11. F. close ()
  12. Def _ del _ (self ):
  13. F=File('StoreFile.txt ', 'A ')
  14. P. dump (notebook. dictnote, f)
  15. F. close ()
  16. Notebook. dictnote= {}
  17. Def delInfo (self, name ):
  18. While notebook. dictnote. _ contains _ (name) = False:
  19. Print "the database does not contain the contact information. Check whether the input is correct! "
  20. Break
  21. Else:
  22. Del notebook. dictnote [name]
  23. # Dictnote. _ delitem _ (name)
  24. F=File('StoreFile.txt ', 'w ')
  25. P. dump (notebook. dictnote, f)
  26. F. close ()
  27. Def addInfo (self, name, phone_number ):
  28. While notebook. dictnote. _ contains _ (name) = True:
  29. Print "this contact information already exists in the Database. Make sure the input is correct! "
  30. Break
  31. Else:
  32. Notebook. dictnote. _ setitem _ (name, phone_number)
  33. Def inquiryInfo (self, name ):
  34. While notebook. dictnote. _ contains _ (name) = False:
  35. Print "the database does not contain the contact information. Check whether the input is correct! "
  36. Break
  37. Else:
  38. Print "the contact name you query is '% s', and the phone number is' % S'" % \
  39. (Name, notebook. dictnote. _ getitem _ (name ))
  40. Def inquiryAll (self ):
  41. Print "the information of all contacts is as follows: \ n % s" % notebook. dictnote
  42. Def amendInfo (self, name ):
  43. Addr=Raw_input("Please confirm the modified address is :")
  44. Notebook. dictnote [name] = addr
  45. Print "the current contact information is:", name, notebook. dictnote [name]
  46. Flag=True
  47. MyNoteBook=Notebook()
  48. WhileFlag= True:
  49. Answer=Raw_input('Make sure you want to "Browse contacts (L)", "query contacts (C)", "add Contacts (T )",\
  50. "Modify contact (X)", "Delete contact (S)", "exit this program (E )"? ')
  51. IfAnswer= 'C ':
  52. Key=Raw_input('Enter the name of the contact you want to query :')
  53. MyNoteBook. inquiryInfo (key)
  54. ElifAnswer= 'T ':
  55. Key_name=Raw_input('Enter the name of the contact you want to add :')
  56. Key_phone=Raw_input('Enter the contact's phone number :')
  57. MyNoteBook. addInfo (key_name, key_phone)
  58. ElifAnswer='S ':
  59. Key=Raw_input('Enter the name of the contact you want to delete :')
  60. MyNoteBook. delInfo (key)
  61. ElifAnswer= 'X ':
  62. Key=Raw_input('Enter the name of the contact you want to modify :')
  63. MyNoteBook. amendInfo (key)
  64. ElifAnswer= 'L ':
  65. MyNoteBook. inquiryAll ()
  66. ElifAnswer= 'E ':
  67. Flag=False
  68. Else:
  69. Print "Make sure you entered the letters 'C', 't','s, and 'E', that is, you want to perform the following operations: Query, add, delete \
  70. And quit! "
  1. Introduction to Python system files
  2. How to correctly use Python Functions
  3. Detailed introduction and analysis of Python build tools
  4. Advantages of Python in PythonAndroid
  5. How to Use the Python module to parse the configuration file?

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.