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 ++)
- # 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 confirm the modified address is :")
- Notebook. dictnote [name] = addr
- Print "the current contact information is:", name, notebook. dictnote [name]
- Flag=True
- MyNoteBook=Notebook()
- WhileFlag= 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 )"? ')
- IfAnswer= 'C ':
- Key=Raw_input('Enter the name of the contact you want to query :')
- MyNoteBook. inquiryInfo (key)
- ElifAnswer= '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)
- ElifAnswer='S ':
- Key=Raw_input('Enter the name of the contact you want to delete :')
- MyNoteBook. delInfo (key)
- ElifAnswer= 'X ':
- Key=Raw_input('Enter the name of the contact you want to modify :')
- MyNoteBook. amendInfo (key)
- ElifAnswer= 'L ':
- MyNoteBook. inquiryAll ()
- ElifAnswer= '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! "
- Introduction to Python system files
- How to correctly use Python Functions
- Detailed introduction and analysis of Python build tools
- Advantages of Python in PythonAndroid
- How to Use the Python module to parse the configuration file?