List of Python Modules

List of Python Modules thumbnail
The Python programming language extends its capabilities with modules.

The Python general purpose programming language is a multiplatform development system supported by the open source community. One of its main strengths is a comprehensive set of object libraries called modules. The modules contain functions and data for handling a variety of tasks. Some of the more commonly-used modules include those for math, operating system parameters, time and zip file processing.

  1. Math

    • The math module consists of mathematical functions and two constants, namely, pi and e, the base for natural logarithms. It covers standard trigonometry, logarithms, absolute value, truncation and factorials. Math.sin(x), for example, returns the value of the sine of the angle x, where x is in radians. Math.sqrt(x) extracts the square root of the value in x. Some functions in math test the value for specific properties; math.isinf(x) tests x for positive or negative infinity.

    OS

    • Python gives you access to a variety of operating system features via its OS module. Python is available for computers using Unix, Microsoft Windows and Mac OSX. Some OS functions work only on Unix due to internal differences in the software. The function os.getlogin(), for example, returns the user’s log-in name for Unix systems only. The os.getenv() and os.putenv() functions return and set the values of environmental variables for Windows and Unix computers. Os.strerror(x) returns a text description of an error when the error code number is in the variable x. The os.access(path, mode) works for Unix and Windows. It returns a true if your user permissions give you access to the disk file directory specified in the path variable with access type mode. For example, if you want to know if you can write to the directory “temp,” set the path variable to “temp,” set the mode variable to “w_ok” and test the function.

    Time

    • The time module has several functions related to the computer’s clock and calendar. The time.sleep(x) function pauses the program’s execution a number of seconds specified in x. The time.time() function returns a raw time value as a number of seconds since the beginning of the operating system’s epoch. Unix, for example, uses January 1, 1970 as the beginning of its epoch. To convert time.time() into a more meaningful local format, the time module has other functions, such as time.localtime(). The function time.altzone() gives the time difference in seconds between your local time zone and UTC standard time in Greenwich, England.

    Zipfile

    • The zip file module allows Python programs to work with compressed archive files in the zip format. A zip file is a set of standard computer files packed together into one to save disk space, create convenient email attachments or encrypt files with a password. The main function in the zip file module is zipfile.ZipFile(file, mode, compression, allowzip64), where the file variable contains the name of the zip file, mode handles reading, writing and appending to a zip file, compression is the file’s compression type, and allowzip64 is an optional true or false value. If true, it lets you create a zip file greater than 2 gigabytes in size.

Related Searches:

References

  • Photo Credit Stockbyte/Stockbyte/Getty Images

Comments

Related Ads

Featured