home


Python-by-example
New Modules
shutil module
tempfile module
traceback module
re: special characters
inspect module
New shorter url: http://pbe.lightbird.net (old will continue to work)

This guide aims to show examples of use of all Python Library Reference functions, methods and classes. At this point, only the more widely used modules were added and only functions use examples are given. Python version 2.5 was used for examples unless noted otherwise. Example of output of a function is shown in the form of function_call(args) # result, when result is the actual output, it is shown after the comment sign, if it's a description of an outcome, e.g. a raised exception, it will be shown in square brackets:

    math.sqrt(9)   # 3.0
    1/0            # [raises ZeroDivisionError]
Note that use of function is shown as if it was imported directly to current namespace, e.g. pow(2,3) instead of math.pow(9).

Built-in functions

sys module - system-specific parameters and functions

pprint module - pretty printing

string module and methods

Regular expressions:

decimal module - decimal floating point arithmetic

array module - efficient representations of arrays

calendar module

math module

random module - pseudo-random number generators

sets module - unordered collections of unique elements

struct module - conversion between Python values and C structs

textwrap module

os.path module

datetime.datetime module

time module

glob module - match filenames by pattern

rlcompleter module - complete valid Python identifiers and keywords

platform module - access to platform's identifying data

shutil module - copyfile, copytree, rmtree, move, ...

tempfile module - generate temporary files and directories

traceback module - print or retrieve a stack traceback

inspect module - inspect live objects such as functions, modules, classes


  links | copyright info