Introduction to common Python modules and python modules

Source: Internet
Author: User
Tags glob ftp client

Introduction to common Python modules and python modules

In addition to keywords and built-in types and functions (builtins), python provides more functions through libraries (modules.

Commonly used libraries (modules) are as follows:

1) python runtime Service

* Copy: The copy module provides the ability to perform shortest copy and deep copy on compound objects (list, tuple, dict, and custom class.

* Pickle: the pickle module is used to serialize python objects to bytes streams, so it is suitable for storing objects, network transmission, or database storage. (The pickle process is also called serializing, marshalling, or flattening. pickle can also be used to deserialize bytes streams into python objects ).

* Sys: the sys module contains the variables and functions related to the python parser and environment.

* Others: atexit, gc, inspect, marshal, traceback, types, warnings, and weakref.

2) Mathematics

* Decimal: float in python is represented by double-precision binary floating-point encoding. This encoding causes decimal numbers not to be accurately expressed. For example, 0.1 is actually 0.100000000000000001 in memory, 3*0.1 = 0.3 is False. decimal is used to solve similar problems. It has higher precision, can represent a larger range of numbers, and is more accurate to rounding.

* Math: The math module defines standard mathematical methods, such as cos (x) and sin (x.

* Random: the random module provides various methods to generate random numbers.

* Others: fractions and numbers.

3) data structure, Algorithm and code simplification

* Array: array indicates an array, similar to list. Different from list, an array can only store objects of the same type.

* Bisect: bisect is an ordered list, in which the binary section is used internally for most operations.

* Collections: the collections module contains some useful high-performance implementations of containers, abstract base classes of various containers, and functions for creating name-tuple objects. For example, deque, defaultdict, and namedtuple containers are included.

* Heapq: heapq is a queue with priority implemented by heap.

* Itertools: itertools contains functions used to create valid iterators. All functions return iterators or include iterators (for example, generators and generators expressions ).

* Operator: operator provides access to python built-in operations and special methods provided by the parser, for example, x + y is add (x, y), x + = y is iadd (x, y), a % B is mod (a, B), and so on.

* Others: abc, contextlib, and functools.

4) string and text Processing

* Codecs: The codecs module is used to process conversion of different character codes and unicode text io.

* Re: The re module is used to match and replace strings with regular expressions.

* String: the string module contains a large number of useful constants and functions used to process strings. It also contains classes in the new string format.

* Struct: the struct module is used to implement conversion between python and binary structures.

* Unicodedata: The unicodedata module provides access to the unicode Character database.

5) python Database Access

* Relational databases share a common Specification for Python Database API Specification V2.0, MySQL, Oracle, and so on. Then, they add their own extensions.

* Sqlite3: The sqlite3 module provides the SQLite database access interface. SQLite databases are self-contained relational databases in the form of a file or memory.

* DBM-style database module: python provides les to support unix dbm-style database files. The dbm module is used to read standard UNIX-dbm database files, gdbm is used to read GNU dbm database files, and dbhash is used to read Berkeley DB database files. All these modules provide an object that implements a string-based persistent dictionary. It is very similar to the dictionary dict, but its keys and values must both be strings.

* Shelve: The shelve module uses special "shelf" objects to support persistent objects. The behavior of this object is similar to that of dict, but all the objects stored in it are stored on the hard disk using hashtable-based databases (dbhash, dbm, gdbm. The difference from the dbm module is that the stored object is not only a string, but also any pickle-compatible object.

6) file and directory Processing

* Bz2: The bz2 module is used to process files compressed by the bzip2 compression algorithm.

* Filecmp: The filecmp module provides functions to compare files and directories.

* Fnmatch: The fnmatch module provides wildcards for UNIX shell-style to match file names. This module is only used for matching. You can use glob to obtain a list of matched files.

* Glob: the glob module returns all files that match the specified UNIX shell wildcard in a directory.

* Gzip: the gzip module provides a class GzipFile for reading and writing files compatible with the GNUgzip program.

* Shutil: The shutil module is used to perform more advanced file operations, such as copying, deleting, and renaming. Shutil operations are intended for general files and do not support pipes, block devices, and other file types.

* Tarfile: The tarfile module is used to maintain the tar archive file. Tar does not support compression.

* Tempfile: The tempfile module is used to generate temporary files and file names.

* Zipfile: The zipfile module is used to process zip files.

* The zlib and zlib modules provide access to the zlib library's compression function.

7) Operating System Services

* Cmflands: the commands module is used to execute simple system commands. commands are passed in as strings and the command output is returned as strings. However, this module is only available on UNIX systems.

* ConfigParser: The configParser module is used to read and write configuration files in the ini format of windows.

* Datetime: The datetime module provides various types to represent and process dates and times.

* Errno, which defines the symbolic names corresponding to all errorcodes.

* Io and io modules implement various IO forms and built-in open () functions.

* The logging module flexibly and conveniently records events, errors, warnings, and debuging information for applications. These logs can be collected, filtered, written to files or system logs, and even sent to remote machines over the network.

* Mmap and mmap modules support memory ing file objects. Memory ing files are similar to General files or byte strings.

* Msvcrt and mscrt can only be used in windows systems. They are used to access many useful functions of the Visual C Runtime Library.

* The optparse and optparse modules process UNIX style command line options sys. argv at a higher level.

* The OS and OS modules provide portable interfaces for general operating system services. OS can be considered as nt and posix abstraction. Nt provides windows service interfaces, and posix provides UNIX (linux, mac) service interfaces.

* The OS. path and OS. path modules process path-related operations in a portable manner.

* The signal and signal modules are used for signal processing, which is often related to synchronization.

* Subprocess: The subprocess module contains functions and objects to create a new process in a unified manner, control the input and output streams of the new process, and process the returned process.

* The time and time modules provide time-related functions. Commonly used time. sleep ().

* Winreg and winreg are used to operate the windows registry.

* Others: fcntl.

8) threads and Parallelism

* The multiprocessing and multiprocessing modules use subprocess to load multiple tasks, communicate, share data, and perform various synchronization operations.

* The threading and threading modules provide many Synchronization Methods for thread classes to implement multi-threaded programming.

* The queue and queue modules implement various multi-producer and multi-consumer queues and are used to implement information security exchange for multi-threaded programs.

* Others: Coroutines and Microthreading.

9) network programming and socket (sockets)

* Asynchat and asynchat simplify Asynchronous Network processing of applications by encapsulating asyncore.

* The ssl module is used to wrap socket objects using secure sockets layer (ssl) to implement data encryption and terminal authentication. Python uses openssl to implement this module.

* The socketserver and socketserver modules simplify the implementation of socket server in the TCP, UDP, and UNIX fields.

* Others: asyncore, select.

10) internet Application Programming

* The ftplib and ftplib modules implement the ftp client protocol. This module is rarely used because urllib provides more advanced interfaces.

* The http package contains the http client and server implementation and cookies management modules.

* Smtplib and smtplib contain the underlying interface of the smtp client, which is used to send emails using the smtp protocol.

* The urllib and urllib packages provide advanced interfaces to implement client interaction with http server, ftp server, and local files.

* Xmlrpc, xmlrpc module is implemented by class XML-RPC client.

11) web Programming

* Cgi and cgi Modules are used to implement cgi scripts. cgi programs are generally executed by webserver to process user input in form or generate dynamic content. When a request with a cgi script is submitted, webserver executes cgi as a sub-process. The cgi program obtains the input through sys. stdin or the environment variable and outputs it through sys. stdout.

* Webbrowser: The webbrowser module provides platform-independent tools and functions to open documents using web browser.

* Others: wsgiref/WSGI (Python Web Server Gateway Interface ).

12) internet Data Processing and encoding

* The base64 module provides base64, base32, and base16 encoding methods for encoding and decoding between binary and text. Base64 is usually used to encode binary data and embed it into a mail or http protocol.

* The binascii and binascii modules provide low-level interfaces to convert binary data and various ASCII codes.

* Csv: the csv module is used to read and write the comma-separated values (CSV) file.

* The email package provides a large number of functions and objects to use the MIME standard for representation, parsing and maintaining email messages.

* The hashlib and hashlib modules implement various secure hash and message digest algorithms, such as MD5 and SHA1.

* Htmlparser (html. parser). This module defines HTMLParser to parse HTML and XHTML documents. To use this class, you must define your own class and inherit from HTMLParser.

* The json module is serialized with a class or a syntax to serialize Javascript object notation (json) objects.

* Xml and xml packages provide various xml processing methods.

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.