Daily Study Notes (3)

Source: Internet
Author: User
Tags signal handler

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 ).

 

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.