Python standard library: built-in function _ import _ (name, globals = None, locals = None, fromlist = (), level = 0) ,__ import _ fromlist
This function implements the function of the import module. This function is implemented mainly for the statement import function. In most cases, you do not need to directly use this function. For example, to dynamically loa
This function implements the Get property of object. Property is represented by name, which is a string of property names. The parameter default is an optional parameter that is returned when the property that gets the object does not exist. Assume that this parameter is not provided. The same time is not found in the object properties, and does not throw an exception attributeerror. Examples:#getattr () class Foo: def __init__ (self): self.x = + foo = foo () print (Ge
arriving at the same time will follow priority is executed sequentially. Execution events are actually executed action(argument) . The argument must be a action sequence that contains parameters.The return value is an event that can be used to cancel the event later (see cancel() ).
Scheduler.enter (delay, priority, action, argument)
Schedule an event to delaydelayUnits of time. In addition to the time, other parameters, meanings, and return valuesenterabs()The same value. In fac
This function is used to delete the properties of an object, such as a property added to the function setattr () , which can be removed using this function. Parameter Object is an object, and the parameter name is a string, but the string must be an object's property. For example , delattr (x, ' test ') is equivalent to del x.test. Examples:#delattr () Class Test:passa = Test () setattr (A, ' foo ', ') print (' A.foo: ', A.foo) delattr (A, ' foo ')The output results are as follows:A.foo:12Cai
This function constructs a new dictionary from a mapped function object.Unlike the dict (**kwarg) function, a parameter input is a function object of a mapping type, such as a zip function,amap function. Examples:#dict () #以键对方式构造字典d1 = dict (one = 1, one = 2, a = 3) print (D1) #以映射函数方式来构造字典d2 = Dict ([' One ', ' one ', ' B ', ' Three '], [1, 2, 3]) ) Print (D2)The output results are as follows:{' A ': 3, ' one ': 1, ' both ': 2}{' Three ': 3, ' one ': 2, ' One ': 1}Cai Junsheng qq:9073204 Shenz
%%"% down_progress,)#%.2f reserved two-bit decimal place,% escape character% for percent sign# print ("%.2f%%"% down_progress)URL1 = "Http://www.iplaypython.com"URL2 = "http://www.python.org"Local = "E:/_python/other/iplaypython.html"# Download the page and show the progress barUrllib.request.urlretrieve (Url1,local,callback)"""1. Incoming URLs, the type of the URL must be a string.2. Incoming, local page save path + file name3. A function call, we can arbitrarily define the behavior of this fun
Tag: Time () use the signal to process frame's own logs amp Port example==signal module = = You can use the ' signal ' module to configure your own signal processor (signal handler), as shown in [Example 3-11 #eg-3-11]. When the interpreter receives a signal, the signal processor executes immediately. ====example 3-11. Use signal module ====[eg-3-11] "File:signal-example-1.pyimport signalimport timedef Handler (Signo, frame): print" got Signal ", signosignal.signal (signal. SIGALRM, handler)
The random module is the module used to generate the stochastic number.
Importing the Random moduleImport Random
Generates a random number of 0~1, floating-point numbers# Randomly generate a random number of 0~1 Print (Random.random ())
Generate any range of floating-point numbers# randomly take a range of floating-point numbers from the list Print (Random.uniform (1,3))
Generate an integer within [x, Y] Range# randomly generate a random number Print (Random.randint (1,3))
Gen
This module is critical if you want your program to be platform-agnostic.Os.name#' NT ' for Windows, ' POSIX ' for Linux/unixOS.GETCWD ()#get current work directory, which is where the Python script worksos.getenv ()#get the environment variablesos.setenv ()#Set the ...Os.listdir (Mdir)#list all files and directories name under MdirOs.remove (mfile)#Delete MfileOs.system ()#Run shell commandOs.linesep#line terminator, ' \ r \ n ' for Windows, ' \ n '
. The
os.linesep string gives the line terminator used by the current platform. For example, Windows uses ' \ r \ n ' , Linux uses ' \ n ' and Mac uses ' \ R ' . The
os.path.split () function returns the directory name and file name of a path. >>> os.path.split ('/home/swaroop/byte/code/poem.txt ') ('/home/swaroop/ Byte/code ', ' poem.txt ')
os.path.isfile () and Os.path.isdir () The function verifies that the given path is a file or a directory, respecti
)
%j
Day of the Year (001-366)
%m
Month (01-12)
%M
Number of minutes (00-59)
%p
Local AM or PM's corresponding character
One
%s
Seconds (01-61)
Two
%u
The number of weeks in a year. (00-53 weeks is the beginning of one weeks.) )All days before the first Sunday are placed in the No. 0 week.
Three
%w
The day of the one week (0-6
Python study Note 10: path and file of the standard library (OS. path package, glob package ),One OS. path packageCheck the Code:
Import OS. pathpath = "/home/User/Document/test.txt" print (OS. path. basename (path) # query the file name print (OS. path. dirname (path) # The query path contains the directory info = OS. path. split (path) # split the path into two
This article mainly introduces the Python standard library OS. path package and glob package usage examples. This article provides the code directly. the code contains detailed comments. For more information, see
OS. path package
The OS. path package is mainly used to process string paths, such as '/home/zikong/doc/file.doc' to extract useful information.
The
Things are a lot more messy this time. Part of the time in doing operations, part of the time to do Development. Always too anxious, always feel very much things do not very comfortable. Still want to calm down to think carefully, spend more time to Improve. Refactoring and Thinking.
Software development is not a tightly written code, finished functions so simple Things-orangeleliu
today, I looked at Python's speech in youtobe, and then looked up what was in it, and just turned to Python's
The standard library IPAddress starts with Python 3.3, which provides methods and classes that can be used to create addresses and networks that manipulate IPv4 and IPv6.
1. A unified approach to creating IP addresses, networks, and interfacesIpaddress.ip_address (' myaddress ') ipaddress.ip_network (' myaddress ', strict=true) ipaddress.ip_interface (' Myaddress
The ==pipes module = = (Unix only) "Pipes" module provides support for "conversion pipeline (conversion pipelines)". You can create pipelines that contain many external tool calls to handle multiple files. As shown in [Example 3-8 #eg-3-8]. ====example 3-8. Use pipes module ====[eg-3-8] "' File:pipes-example-1.pyimport pipest = pipes. Template () # Create a pipeline# Here "-" represents reading from the standard input content t.append ("Sort", "--") T
song on the XY plane to a point on the hexagonal grid.Back to the original high dimensional feature space, the song clustering to the user-defined number of groups (k=10 can achieve a good visual purposes). For each group, find the song closest to the group center.On the hexagonal grid, use different colors to color the song in the K Group Center.Insert a different color into each of the other songs, depending on the distance to the center of each group on the XY screen.
Next, let's take a loo
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.