Practical application solution for creating command lines using Python applets

Source: Internet
Author: User

If you are confused about the actual operation steps of the Python applet, you can refer to the following article for a detailed understanding of the Python applet, this article describes how to use it to create your own command line Address Book Program and modify, delete, and search for your contacts and their information.

Because we need to do something about electronic chart display, we can see on the relevant forum that some Daniel said that the combination of GDAL and PIL can easily draw vector graphics. 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 develop such a program,

That is, create your own command line Address Book Program. In this program, you can add, modify, delete, and search for your contacts and their information. The details should be saved for future extraction.

After several hours of hard work, the Python applet 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. View plaincopy to clipboardprint?
  2. # MyFirstIntegratedPythonProgram
  3. Import cPickle as P
  4. Class notebook:
  5. Dictnote = {}
  6. Def _ init _ (self ):
  7. Notebook. dictnote = {'Randy ': '123 ',
  8. 'Jackson ': '123 ',
  9. 'Mary ': '000000 '}
  10. F=file('storeFile.txt ', 'A ')
  11. P. dump (notebook. dictnote, f)
  12. F. close ()
  13. Def _ del _ (self ):
  14. F=file('storeFile.txt ', 'A ')
  15. P. dump (notebook. dictnote, f)
  16. F. close ()
  17. Notebook. dictnote = {}
  18. Def delInfo (self, name ):
  19. While notebook. dictnote. _ contains _ (name) = False:
  20. Print "the database does not contain the contact information. Check whether the input is correct! "
  21. Break
  22. Else:
  23. Del notebook. dictnote [name]
  24. # Dictnote. _ delitem _ (name)
  25. F=file('storeFile.txt ', 'w ')
  26. P. dump (notebook. dictnote, f)
  27. F. close ()
  28. Def addInfo (self, name, phone_number ):
  29. While notebook. dictnote. _ contains _ (name) = True:
  30. Print "this contact information already exists in the Database. Make sure the input is correct! "
  31. Break
  32. Else:
  33. Notebook. dictnote. _ setitem _ (name, phone_number)
  34. Def inquiryInfo (self, name ):
  35. While notebook. dictnote. _ contains _ (name) = False:
  36. Print "the database does not contain the contact information. Check whether the input is correct! "
  37. Break
  38. Else:
  39. Print "the contact name you query is '% s', and the phone number is' % S'" % \
  40. (Name, notebook. dictnote. _ getitem _ (name ))
  41. Def inquiryAll (self ):
  42. Print "the information of all contacts is as follows: \ n % s" % notebook. dictnote
  43. Def amendInfo (self, name ):
  44. Addr = raw_input ("Please make sure the modified address is :")
  45. Notebook. dictnote [name] = addr
  46. Print "the current contact information is:", name, notebook. dictnote [name]
  47. Flag = True
  48. MyNoteBook = notebook ()
  49. While flag = True:
  50. Answer = raw_input ('make sure you want to "Browse contacts (L)", "query contacts (C)", "add Contacts (T )",\
  51. "Modify contact (X)", "Delete contact (S)", "exit this program (E )"? ')
  52. If answer = 'C ':
  53. Key = raw_input ('Enter the name of the contact you want to query :')
  54. MyNoteBook. inquiryInfo (key)
  55. Elif answer = 'T ':
  56. Key_name = raw_input ('Enter the name of the contact you want to add :')
  57. Key_phone = raw_input ('Enter the contact's phone number :')
  58. MyNoteBook. addInfo (key_name, key_phone)
  59. Elif answer ='s ':
  60. Key = raw_input ('Enter the name of the contact you want to delete :')
  61. MyNoteBook. delInfo (key)
  62. Elif answer = 'X ':
  63. Key = raw_input ('Enter the name of the contact you want to modify :')
  64. MyNoteBook. amendInfo (key)
  65. Elif answer = 'l ':
  66. MyNoteBook. inquiryAll ()
  67. Elif answer = 'E ':
  68. Flag = False
  69. Else:
  70. Print "Make sure you entered the letters 'C', 't','s, and 'E', that is, you want to perform the following operations: Query, add, delete \
  71. And quit! "
  72. # MyFirstIntegratedPythonProgram
  73. Import cPickle as P
  74. Class notebook:
  75. Dictnote = {}
  76. Def _ init _ (self ):
  77. Notebook. dictnote = {'Randy ': '123 ',
  78. 'Jackson ': '123 ',
  79. 'Mary ': '000000 '}
  80. F=file('storeFile.txt ', 'A ')
  81. P. dump (notebook. dictnote, f)
  82. F. close ()
  83. Def _ del _ (self ):
  84. F=file('storeFile.txt ', 'A ')
  85. P. dump (notebook. dictnote, f)
  86. F. close ()
  87. Notebook. dictnote = {}
  88. Def delInfo (self, name ):
  89. While notebook. dictnote. _ contains _ (name) = False:
  90. Print "the database does not contain the contact information. Check whether the input is correct! "
  91. Break
  92. Else:
  93. Del notebook. dictnote [name]
  94. # Dictnote. _ delitem _ (name)
  95. F=file('storeFile.txt ', 'w ')
  96. P. dump (notebook. dictnote, f)
  97. F. close ()
  98. Def addInfo (self, name, phone_number ):
  99. While notebook. dictnote. _ contains _ (name) = True:
  100. Print "this contact information already exists in the Database. Make sure the input is correct! "
  101. Break
  102. Else:
  103. Notebook. dictnote. _ setitem _ (name, phone_number)
  104. Def inquiryInfo (self, name ):
  105. While notebook. dictnote. _ contains _ (name) = False:
  106. Print "the database does not contain the contact information. Check whether the input is correct! "
  107. Break
  108. Else:
  109. Print "the contact name you query is '% s', and the phone number is' % S'" % \
  110. (Name, notebook. dictnote. _ getitem _ (name ))
  111. Def inquiryAll (self ):
  112. Print "the information of all contacts is as follows: \ n % s" % notebook. dictnote
  113. Def amendInfo (self, name ):
  114. Addr = raw_input ("Please make sure the modified address is :")
  115. Notebook. dictnote [name] = addr
  116. Print "the current contact information is:", name, notebook. dictnote [name]
  117.  
  118.  
  119.  
  120. Flag = True
  121. MyNoteBook = notebook ()
  122. While flag = True:
  123. Answer = raw_input ('make sure you want to "Browse contacts (L)", "query contacts (C)", "add Contacts (T )",\
  124. "Modify contact (X)", "Delete contact (S)", "exit this program (E )"? ')
  125.  
  126. If answer = 'C ':
  127. Key = raw_input ('Enter the name of the contact you want to query :')
  128. MyNoteBook. inquiryInfo (key)
  129.  
  130. Elif answer = 'T ':
  131. Key_name = raw_input ('Enter the name of the contact you want to add :')
  132. Key_phone = raw_input ('Enter the contact's phone number :')
  133. MyNoteBook. addInfo (key_name, key_phone)
  134.  
  135. Elif answer ='s ':
  136. Key = raw_input ('Enter the name of the contact you want to delete :')
  137. MyNoteBook. delInfo (key)
  138.  
  139. Elif answer = 'X ':
  140. Key = raw_input ('Enter the name of the contact you want to modify :')
  141. MyNoteBook. amendInfo (key)
  142.  
  143. Elif answer = 'l ':
  144. MyNoteBook. inquiryAll ()
  145.  
  146. Elif answer = 'E ':
  147. Flag = False
  148. Else:
  149.  

Print "Make sure you entered the letters 'C', 't', 's', and 'E', that is, you want to perform the following operations: Query, add, delete, and exit! "The above article introduces how to create command lines, address books, and programs for Python applets.

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.