1. Let's talk about the most profound thing today: Writing Python code, a good editor is crucial, and VIM is indeed the best choice. Because Python judges the context based on indentation, improper use of tabs and spaces will kill you. The alignment format of a piece of code in Notepad ++ seems to be okay, but the Code cannot be compiled in real time. Let's take a look at the next part of VIM. The format of damn it is messy. I wanted to replace all the tabs with four spaces, but the damn notepad ++ didn't replace all the tabs, and then changed ultraedit32. It was still the last thing to do. I finally changed emeditor, better than the first two,
2. Python traverses all files in the folder
Code
For root, dirs, files in OS. Walk (sdir, topdown = false ):
For file in files:
Full_path = sdir + File
If OS. Path. exists (full_path) = true:
# Process File
3. Python processes command line parameters
Code
Import sys
Import getopt
While true:
Try:
Opts, argS = getopt. getopt (sys. argv [1:], "HS: T: D: I", ["help", "Source =", "targe =", "IP ="])
For opt, ARG in opts:
If opt in ("-h", "-- Help "):
Print ("Show Help info/N ")
Elif opt in ("-T", "-- targe "):
Target = ARG
Elif opt in ("-s", "-- source "):
Source = ARG
Elif opt in ("-e", "-- exit "):
SYS. Exit (0)
Counter t getopt. getopterror:
SYS. Exit (-1)
4. Signal Processing Mechanism in Python
Code
Import Signal
Def handler (SIGNUM, frame ):
Print 'signal handler called with signal ', SIGNUM
Raise timeouterror, "timeout! "
Try:
# Set the signal handler and a 1-second alarm
Signal. Signal (signal. sigalrm, Handler)
Signal. Alarm (1)
# This while loop hang indefinitely
While true:
Print 'A ',
Signal. Alarm (0) # disable the alarm
Except t:
Print
Print 'Time out caught! '
5. MySQL common points: 1) truncate table tablename is used to delete all data in the table. 2) limit is equivalent to the top of other databases and takes the specified number of records. 3) DESC table name is used to view the table structure. 4) if the field in the table is a keyword such as group, you need to use 'group' (not a single quotation mark, it is the key next to number 1 ).