Python module Daquan

Source: Internet
Author: User
Tags local time md5 encryption readline stdin

Ext.: http://blog.csdn.net/hwhjava/article/details/22284399

********************
Py Core Module method
********************
OS module:
Os.remove () deleting files
Os.unlink () deleting files
Os.rename () Renaming files
Os.listdir () lists all files in the specified directory
Os.chdir () Change the current working directory
OS.GETCWD () Gets the current file path
Os.mkdir () New directory
Os.rmdir () Delete empty directory (delete non-empty directory, use Shutil.rmtree ())
Os.makedirs () Create a multilevel directory
Os.removedirs () Deleting a multilevel directory
Os.stat (file) to get the properties of files
Os.chmod (file) Modify permissions
Os.utime (file) to modify timestamp
Os.name (file) Gets the operating system identity
Os.system () Executing operating system commands
OS.EXECVP () Start a new process
Os.fork () Gets the parent process ID and returns 0 in the child process return
OS.EXECVP () Execute External program script (Uinx)
Os.spawn () Execute External program script (Windows)
Os.access (path, mode) to determine file permissions (detailed reference cnblogs)
Os.wait () temporarily unknown
Os.path module:
Os.path.split (filename) splits the file path and filename (the last directory is separated as the file name)
Os.path.splitext (filename) splits the file path and file name extension into a single tuple
Os.path.dirname (filename) returns the directory portion of the file path
Os.path.basename (filename) returns the filename portion of the file path
Os.path.join (dirname,basename) the file path and filename into the full file path
Os.path.abspath (name) gets the absolute path
Os.path.splitunc (path) splits the path into mount point and file name
Os.path.normpath (path) canonical path string form
Os.path.exists () Determine if a file or directory exists
Os.path.isabs () returns True if path is an absolute path
Os.path.realpath (PATH) #返回path的真实路径
Os.path.relpath (path[, start]) #从start开始计算相对路径
Os.path.normcase (PATH) #转换path的大小写和斜杠
Os.path.isdir () Determine if name is a directory, name is not a directory and return false
Os.path.isfile () determines if name is not a file and does not exist return false
Os.path.islink () Determines whether the file is connected to a file, returns a Boolean
Os.path.ismount () Specifies whether the path exists and is a mount point, returning a Boolean
Os.path.samefile () is a file with the same path, returns a Boolean
Os.path.getatime () returns the most recent access time floating-point type
Os.path.getmtime () returns the last modified time floating-point type
Os.path.getctime () returns the file creation time floating-point type
Os.path.getsize () returns the file size byte units
Os.path.commonprefix (list) #返回list (multiple paths), the longest path common to all paths
Os.path.lexists #路径存在则返回True, path corruption also returns true
Os.path.expanduser (path) #把path中包含的 "~" and "~user" to the user directory
Os.path.expandvars (path) #根据环境变量的值替换path中包含的 "$name" and "${name}"
Os.path.sameopenfile (FP1, FP2) #判断fp1和fp2是否指向同一文件
Os.path.samestat (STAT1, STAT2) #判断stat tuple STAT1 and Stat2 point to the same file
Os.path.splitdrive (path) #一般用在windows下, returns a tuple of drive names and paths
Os.path.walk (path, visit, Arg) #遍历path, perform a function for each path in detail in the manual
Os.path.supports_unicode_filenames () sets whether Unicode path names are supported
Stat module:
Describes the meaning of the values in the list of file attributes returned by Os.stat ()
Filestats = Os.stat (path) Gets the list of file attributes
Filestats[stat. St_mode] Get the file mode
Filestats[stat. St_size] File size
Filestats[stat. St_mtime] File Last modified time
Filestats[stat. St_atime] File last accessed time
Filestats[stat. St_ctime] File creation time
Stat. S_isdir (Filestats[stat. St_mode]) Whether the directory
Stat. S_isreg (Filestats[stat. St_mode]) are general documents
Stat. S_islnk (Filestats[stat. St_mode]) Whether the file is connected
Stat. S_issock (Filestats[stat. St_mode]) Whether cock file
Stat. S_isfifo (Filestats[stat. St_mode]) whether to name the pipe
Stat. S_isblk (Filestats[stat. St_mode]) is a block device
Stat. S_ISCHR (Filestats[stat. St_mode]) Whether the character is set
SYS module:
SYS.ARGV command line argument list, the first element is the path of the program itself
Sys.path returns the search path for the module, using the value of the PYTHONPATH environment variable when initializing
Sys.modules.keys () returns the list of all modules that have been imported
Sys.modules returns the module field of the system import, key is the module name, value is the module
Sys.exc_info () Gets the exception class currently being processed, Exc_type, Exc_value, exc_traceback the exception details currently handled
Sys.exit (n) exit program, Exit normally (0)
Sys.hexversion gets the version value of the Python interpreter, 16 binary format such as: 0x020403f0
Sys.version get version information for Python interpreter
Sys.platform returns the operating system platform name
Sys.stdout Standard Output
Sys.stdout.write (' AAA ') standard output content
Sys.stdout.writelines () No Line break output
Sys.stdin Standard input
Sys.stdin.read () Enter a row
Sys.stderr Error Output
Sys.exc_clear () to clear current or recent error messages that are present on the current thread
Sys.exec_prefix returns the location of the platform standalone Python file installation
Sys.byteorder The local byte rule indicator, the value of the Big-endian platform is ' big ', the value of the Little-endian platform is ' little '
Sys.copyright record python copyright-related things
API version of C for the Sys.api_version interpreter
Sys.version_info ' final ' indicates the final, also ' candidate ' represents a candidate, indicating the version level, whether there is a subsequent release
Sys.getdefaultencoding () returns the default character encoding format you are currently using
Sys.getfilesystemencoding () Returns the encoded name of the Unicode file name converted to the system file name
List of built-in modules imported by the Sys.builtin_module_names Python interpreter
Sys.executable Python interpreter path
Sys.getwindowsversion () Get the version of Windows
Sys.stdin.readline () reads a line from the standard input, Sys.stdout.write ("a") screen output a
Sys.setdefaultencoding (name) is used to set the current default character encoding (use the Reference document in detail)
Sys.displayhook (value) if value is not NULL, the function will output it to sys.stdout (use the Reference document in detail)

Datetime,date,time module:
Datetime.date.today () Local Date object (with the STR function to get its literal representation (2014-03-24))
Datetime.date.isoformat (obj) Current [year-month-day] string representation (2014-03-24)
Datetime.date.fromtimestamp () Returns a Date object, the parameter is a timestamp, returns [year-month-day]
Datetime.date.weekday (obj) returns the day of the week for a Date object, Monday is 0
Datetime.date.isoweekday (obj) returns the day of the week for a Date object, Monday is 1
Datetime.date.isocalendar (obj) returns a Date object with a tuple with a month and a day
DateTime object:
Datetime.datetime.today () returns a DateTime object containing the local time (with microseconds) 2014-03-24 23:31:50.419000
Datetime.datetime.now ([TZ]) returns the DateTime object for the specified time zone 2014-03-24 23:31:50.419000
Datetime.datetime.utcnow () returns a DateTime object of 0 time zone
Datetime.fromtimestamp (Timestamp[,tz]) returns a DateTime object by timestamp, specifying the time zone, which can be used to strftime convert to a date representation
Datetime.utcfromtimestamp (timestamp) returns a Utc-datetime object by time stamp
Datetime.datetime.strptime (' 2014-03-16 12:21:21 ', '%y-%m-%d%h:%m:%s ') convert a string to a DateTime object
Datetime.datetime.strftime (Datetime.datetime.now (), '%y%m%d%h%m%s ') converts a DateTime object to a str representation
Datetime.date.today (). Timetuple () Convert to timestamp datetime tuple object, which can be used to convert timestamps
Datetime.datetime.now (). Timetuple ()
Time.mktime (Timetupleobj) to convert a DateTime tuple object to a timestamp
Time.time () Current timestamp
Time.localtime
Time.gmtime


HASHLIB,MD5 module:
HASHLIB.MD5 (' Md5_str '). Hexdigest () MD5 encryption on the specified string
MD5.MD5 (' Md5_str '). Hexdigest () MD5 encryption on the specified string

Random module:
Random.random () generates 0-1 of random floating-point numbers
Random.uniform (A, b) generates random floating-point numbers within a specified range
Random.randint (A, B) produces a random integer within a specified range
Random.randrange ([start], stop[, step]) generates a random number from a set of specified steps
Random.choice (sequence) produces a random number from the sequence
Random.shuffle (x[, random]) disrupts elements in a list
Random.sample (sequence, k) randomly fetches fragments of a specified length from a sequence

Types Module:
All data type names are saved.
If type (' 1111 ') = = types. StringType:
MYSQLDB module:
Mysqldb.get_client_info () Get API version
Mysqldb.binary (' string ') into binary data form
mysqldb.escape_string (' str ') character escaping function for MySQL
Mysqldb.datefromticks (1395842548) convert timestamp to Datetime.date object instance
Mysqldb.timestampfromticks (1395842548) convert timestamp to Datetime.datetime object instance
Mysqldb.string_literal (' str ') character escapes
Mysqldb.cursor () method on the Cursor object: "Python core programming" P624

Atexit module:
Atexit.register (FUN,ARGS,ARGS2.) Register function func, call the function before the parser exits


String module:
Str.capitalize () capitalizes the first character of a string
Str.center (width) returns the center of the original string and fills the new string with a space to the width length
Str.ljust (width) Returns a string that is left-aligned with a space padding to a new string of the specified length
Str.rjust (width) returns the right alignment of the original string, padding the new string to a specified length with a space
Str.zfill (width) returns the right alignment of a string, preceded by a 0 padding to a new string of the specified length
Str.count (Str,[beg,len]) returns the number of occurrences of the substring in the original string, Beg,len is the range
Str.decode (Encodeing[,replace]) decoding string, error throwing ValueError exception
Str.encode (Encodeing[,replace]) decoding string
Str.endswith (Substr[,beg,end]) whether the string ends with Substr, Beg,end is the range
Str.startswith (Substr[,beg,end]) whether the string starts with substr, Beg,end is the range
Str.expandtabs (tabsize = 8) Converts the tab of a string to a space, the default is 8
Str.find (Str,[stat,end]) finds the substring where the string first appears, otherwise returns-1
Str.index (Str,[beg,end]) finds the position of a substring within a specified character, no report exception exists
Str.isalnum () checks whether the string is composed of letters and numbers, and returns true otherwise false
Str.isalpha () checks whether the string is composed of pure letters, returns TRUE, otherwise false
Str.isdecimal () checks whether a string consists of a pure decimal number and returns a Boolean value
Str.isdigit () checks whether a string consists of a pure number, returns a Boolean value
Str.islower () checks whether the string is all lowercase, returns a Boolean value
Str.isupper () checks whether the string is all uppercase, returns a Boolean value
Str.isnumeric () checks whether a string contains only numeric characters, returns a Boolean value
Str.isspace () returns True if Str contains only spaces, false otherwise
Str.title () returns the heading string (all words capitalized, the remaining lowercase)
Str.istitle () returns True if the string is heading (see Title ()), otherwise false
Str.join (seq) joins a sequence of elements into a string using str as the connector
Str.split (str= ", num) separates a string into a sequence using str as a delimiter, and num is a delimited string
Str.splitlines (num) is separated by rows, returning the contents of each row as a list of elements
Str.lower () convert uppercase to lowercase
Str.upper () Converts a string to uppercase in lowercase
Str.swapcase () The case of a string to be flipped
Str.lstrip () Remove whitespace and carriage return line characters to the left of the character
Str.rstrip () Remove the space to the right of the character and return line feed
Str.strip () Remove whitespace and carriage return line breaks on both sides of the character
Str.partition (substr) divides str into a 3-tuple from the first position appearing in substr.
Str.replace (str1,str2,num) Find str1 Replace with Str2,num is the number of replacements
Str.rfind (Str[,beg,end]) querying substrings from the right
Str.rindex (Str,[beg,end]) Find sub-string position starting from the right
Str.rpartition (str) is similar to the partition function, but looks from the right.
Str.translate (str,del= ") converts the string character by the table given by STR, and Del is the character

Urllib module:
Urllib.quote (String[,safe]) encodes a string. The parameter safe specifies a character that does not need to be encoded
Urllib.unquote (String) to decode a string
Urllib.quote_plus (String[,safe]) is similar to Urllib.quote, but this method uses ' + ' to replace ', and quote uses '%20 ' instead of '
Urllib.unquote_plus (String) to decode a string
Urllib.urlencode (Query[,doseq]) converts a dict or a list of tuples containing two elements into a URL parameter.
For example, the dictionary {' name ': ' Wklken ', ' pwd ': ' 123 '} will be converted to ' name=wklken&pwd=123 '
Urllib.pathname2url (path) converts a local path to a URL path
Urllib.url2pathname (path) to convert URL path to cost path
Urllib.urlretrieve (Url[,filename[,reporthook[,data]]) download remote data to local
FileName: Specifies the path to be saved locally (Urllib generates a temporary file to save the data if it is not specified)
Reporthook: callback function that triggers the callback when the server is connected and the corresponding data block is transferred.
Data: Refers to post to the server
Rulrs = Urllib.urlopen (Url[,data[,proxies]]) crawl web information, [data]post data to Url,proxies settings agent
Urlrs.readline () is used as a file object
Urlrs.readlines () is used as a file object
Urlrs.fileno () is used as a file object
Urlrs.close () is used as a file object
Urlrs.info () returns a httplib. Httpmessage object that represents the header information returned by the remote server
Urlrs.getcode () Get Request return status HTTP status code
Urlrs.geturl () returns the requested URL

URLLIB2 module:
Urlparse module:


Re module:
Regular expression module function: "Python core programming" P472
Math,cmath module:
Mathematical operations, complex arithmetic functions
Operator module:
A collection of some numeric manipulation functions. Reference CSDN Collection
Copy module:
Copy.copy (a) Copying objects
Copy.deepcopy (a) Copy collection

Fileinput module:
Working with file content modules
Shutil module:
Contains some functions for copying files and folders:



Python module Daquan

Related Article

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.