This article mainly introduces some of the main methods of main class thread in the threading module, the example code is as follows:
Copy Code code as follows:
'''
Created on 2012-9-7
@author: walfred
@module: Thread.
Python's interpretive language also has a dedicated threading model, with the Python virtual machine using Gil (Global interpreter lock, the globe interpreter Lock) to mutually exclusive threads accessing shared resources, but temporarily unable to
Built-in method description
__init__ (self,...) Initializes an object that is called when a new object is created
__del__ (self) Frees the object and calls it before the object is deleted
Build actions for __new__ (CLS,*ARGS,**KWD) instances
Python supports multithreading and is a native thread. Mainly through the thread and threading these two modules to achieve. Thread is the lower level of the module, threading is the thread made some packaging, can be more convenient to use. One
Module overview
If the module is a logical way to organize Python code, then the file is the method of organizing the module on the physical layer.Therefore, * * A file is considered to be a stand-alone module, and a module can also be considered
The python exception handling mechanism is similar to Java, using a try-except-finally structure.
Try-except Detection exception
Format
Copy Code code as follows:
Try
Try_statement
Except (ErrorType1, ErrorType2), E:
Before understanding the adorner must first understand the function as a parameter pass, what is the function embedded, please refer to the blog function I wrote earlier introduction
Because in Python, a function is also an object, and it can be
Recently research on CSS, not to go online analysis of other people's Web pages, but many of the Web site's CSS files are either written in one line, or a line is not, it seems extremely painful, so write a script to convert to a more readable
Recently, I want to increase the extraction of user operating system version information in my Youmoney (http://code.google.com/p/youmoney/). For example, Windows users may want to return to Windows XP or Windows 2003, and Apple users should return
Join method: Block thread until the thread has finished executing
Therefore, you can add a timeout operation to the join, join ([timeout]), exceed the set time, and no longer block the thread
Jion Plus another consequence is that the child thread
Starting from a string
View a code slice from my Code chip
>>>time_str= ' 2008-08-08 08:08:08 '
1.1. Conversion to struct_time form of time
View a code slice from my Code chip
>>struct = Ime.strptime (time_str,
1. If the module is imported, the __name__ value is the module name2. If the module is executed directly, the value of __name__ is ' __main__ '
py1.py
Copy Code code as follows:
#! /usr/bin/env python
def test ():
print ' __name__
A reference is an address that holds a value that is an object. In the Python language, the values saved by a variable are referenced except for the basic type, so it is necessary to be careful about their use. Here's an example:
Problem
When you touch python, you see the function in the class with the self argument, and you never know what the reason for the leper is. I looked at the self for Python at night, and Daniel.
The reason Python wants self
There is a distinct difference
Returns a string that is stripped of the specified character
Remove white space characters by default
Remove the end character: Str.strip ([char])Delete First character: Str.lstrip ([char])Delete tail character str.strip ([char])
Determines
Format
Getopt (args, options[, long_options])
1.args represents the parameters to resolve.2.options indicates the character to be recognized by the script. The characters are delimited by ":" and Must End with ":", such as "A:B:C:".3.long_options
This article illustrates how Python uses urlparse to analyze domain names in Web addresses. Share to everyone for your reference. Specifically as follows:
Given the URL here, the following Python code makes it easy to get domain information
This article is an example of how Python obtains native extranet IP. Share to everyone for your reference. Specifically as follows:
Python Gets the native extranet IP from the Web site that displays the IP address, and this Python code crawls the
This article illustrates how Python uses the multiprocessing module to implement asynchronous invocation methods with callback functions. Share to everyone for your reference. The specific analysis is as follows:
The Multipressing module is joined
The example in this article describes how Python renames a file in a specified directory in bulk. Share to everyone for your reference. Specifically as follows:
This Python code can be replaced with "scroll_00" for all file names "Scroll_1" in the
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