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 ++)
- View plaincopy to clipboardprint?
- # MyFirstIntegratedPythonProgram
- Import cPickle as P
- Class notebook:
- Dictnote = {}
- Def _ init _ (self ):
- Notebook. dictnote = {'Randy ': '123 ',
- 'Jackson ': '123 ',
- 'Mary ': '000000 '}
- F=file('storeFile.txt ', 'A ')
- P. dump (notebook. dictnote, f)
- F. close ()
- Def _ del _ (self ):
- F=file('storeFile.txt ', 'A ')
- P. dump (notebook. dictnote, f)
- F. close ()
- Notebook. dictnote = {}
- Def delInfo (self, name ):
- While notebook. dictnote. _ contains _ (name) = False:
- Print "the database does not contain the contact information. Check whether the input is correct! "
- Break
- Else:
- Del notebook. dictnote [name]
- # Dictnote. _ delitem _ (name)
- F=file('storeFile.txt ', 'w ')
- P. dump (notebook. dictnote, f)
- F. close ()
- Def addInfo (self, name, phone_number ):
- While notebook. dictnote. _ contains _ (name) = True:
- Print "this contact information already exists in the Database. Make sure the input is correct! "
- Break
- Else:
- Notebook. dictnote. _ setitem _ (name, phone_number)
- Def inquiryInfo (self, name ):
- While notebook. dictnote. _ contains _ (name) = False:
- Print "the database does not contain the contact information. Check whether the input is correct! "
- Break
- Else:
- Print "the contact name you query is '% s', and the phone number is' % S'" % \
- (Name, notebook. dictnote. _ getitem _ (name ))
- Def inquiryAll (self ):
- Print "the information of all contacts is as follows: \ n % s" % notebook. dictnote
- Def amendInfo (self, name ):
- Addr = raw_input ("Please make sure the modified address is :")
- Notebook. dictnote [name] = addr
- Print "the current contact information is:", name, notebook. dictnote [name]
- Flag = True
- MyNoteBook = notebook ()
- While flag = True:
- Answer = raw_input ('make sure you want to "Browse contacts (L)", "query contacts (C)", "add Contacts (T )",\
- "Modify contact (X)", "Delete contact (S)", "exit this program (E )"? ')
- If answer = 'C ':
- Key = raw_input ('Enter the name of the contact you want to query :')
- MyNoteBook. inquiryInfo (key)
- Elif answer = 'T ':
- Key_name = raw_input ('Enter the name of the contact you want to add :')
- Key_phone = raw_input ('Enter the contact's phone number :')
- MyNoteBook. addInfo (key_name, key_phone)
- Elif answer ='s ':
- Key = raw_input ('Enter the name of the contact you want to delete :')
- MyNoteBook. delInfo (key)
- Elif answer = 'X ':
- Key = raw_input ('Enter the name of the contact you want to modify :')
- MyNoteBook. amendInfo (key)
- Elif answer = 'l ':
- MyNoteBook. inquiryAll ()
- Elif answer = 'E ':
- Flag = False
- Else:
- 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 quit! "
- # MyFirstIntegratedPythonProgram
- Import cPickle as P
- Class notebook:
- Dictnote = {}
- Def _ init _ (self ):
- Notebook. dictnote = {'Randy ': '123 ',
- 'Jackson ': '123 ',
- 'Mary ': '000000 '}
- F=file('storeFile.txt ', 'A ')
- P. dump (notebook. dictnote, f)
- F. close ()
- Def _ del _ (self ):
- F=file('storeFile.txt ', 'A ')
- P. dump (notebook. dictnote, f)
- F. close ()
- Notebook. dictnote = {}
- Def delInfo (self, name ):
- While notebook. dictnote. _ contains _ (name) = False:
- Print "the database does not contain the contact information. Check whether the input is correct! "
- Break
- Else:
- Del notebook. dictnote [name]
- # Dictnote. _ delitem _ (name)
- F=file('storeFile.txt ', 'w ')
- P. dump (notebook. dictnote, f)
- F. close ()
- Def addInfo (self, name, phone_number ):
- While notebook. dictnote. _ contains _ (name) = True:
- Print "this contact information already exists in the Database. Make sure the input is correct! "
- Break
- Else:
- Notebook. dictnote. _ setitem _ (name, phone_number)
- Def inquiryInfo (self, name ):
- While notebook. dictnote. _ contains _ (name) = False:
- Print "the database does not contain the contact information. Check whether the input is correct! "
- Break
- Else:
- Print "the contact name you query is '% s', and the phone number is' % S'" % \
- (Name, notebook. dictnote. _ getitem _ (name ))
- Def inquiryAll (self ):
- Print "the information of all contacts is as follows: \ n % s" % notebook. dictnote
- Def amendInfo (self, name ):
- Addr = raw_input ("Please make sure the modified address is :")
- Notebook. dictnote [name] = addr
- Print "the current contact information is:", name, notebook. dictnote [name]
-
-
-
- Flag = True
- MyNoteBook = notebook ()
- While flag = True:
- Answer = raw_input ('make sure you want to "Browse contacts (L)", "query contacts (C)", "add Contacts (T )",\
- "Modify contact (X)", "Delete contact (S)", "exit this program (E )"? ')
-
- If answer = 'C ':
- Key = raw_input ('Enter the name of the contact you want to query :')
- MyNoteBook. inquiryInfo (key)
-
- Elif answer = 'T ':
- Key_name = raw_input ('Enter the name of the contact you want to add :')
- Key_phone = raw_input ('Enter the contact's phone number :')
- MyNoteBook. addInfo (key_name, key_phone)
-
- Elif answer ='s ':
- Key = raw_input ('Enter the name of the contact you want to delete :')
- MyNoteBook. delInfo (key)
-
- Elif answer = 'X ':
- Key = raw_input ('Enter the name of the contact you want to modify :')
- MyNoteBook. amendInfo (key)
-
- Elif answer = 'l ':
- MyNoteBook. inquiryAll ()
-
- Elif answer = 'E ':
- Flag = False
- Else:
-
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.