Python Library Reference - MIT

Python Library Reference

Release 2.1.1

Guido van Rossum Fred L. Drake, Jr., editor

July 20, 2001

PythonLabs E-mail: python-docs@

Copyright c 2001 Python Software Foundation. All rights reserved. Copyright c 2000 . All rights reserved. Copyright c 1995-2000 Corporation for National Research Initiatives. All rights reserved. Copyright c 1991-1995 Stichting Mathematisch Centrum. All rights reserved. See the end of this document for complete license and permissions information.

Abstract

Python is an extensible, interpreted, object-oriented programming language. It supports a wide range of applications, from simple text processing scripts to interactive WWW browsers.

While the Python Reference Manual describes the exact syntax and semantics of the language, it does not describe the standard library that is distributed with the language, and which greatly enhances its immediate usability. This library contains built-in modules (written in C) that provide access to system functionality such as file I/O that would otherwise be inaccessible to Python programmers, as well as modules written in Python that provide standardized solutions for many problems that occur in everyday programming. Some of these modules are explicitly designed to encourage and enhance the portability of Python programs.

This library reference manual documents Python's standard library, as well as many optional library modules (which may or may not be available, depending on whether the underlying platform supports them and on the configuration choices made at compile time). It also documents the standard types of the language and its built-in functions and exceptions, many of which are not or incompletely documented in the Reference Manual.

This manual assumes basic knowledge about the Python language. For an informal introduction to Python, see the Python Tutorial; the Python Reference Manual remains the highest authority on syntactic and semantic questions. Finally, the manual entitled Extending and Embedding the Python Interpreter describes how to add new extensions to Python and how to embed it in other applications.

CONTENTS

1 Introduction

1

2 Built-in Types, Exceptions and Functions

3

2.1 Built-in Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

2.2 Built-in Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

2.3 Built-in Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

3 Python Runtime Services

29

3.1 sys -- System-specific parameters and functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

3.2 gc -- Garbage Collector interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

3.3 weakref -- Weak references . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

3.4 fpectl -- Floating point exception control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

3.5 atexit -- Exit handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

3.6 types -- Names for all built-in types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

3.7 UserDict -- Class wrapper for dictionary objects . . . . . . . . . . . . . . . . . . . . . . . . . . 43

3.8 UserList -- Class wrapper for list objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

3.9 UserString -- Class wrapper for string objects . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

3.10 operator -- Standard operators as functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

3.11 inspect -- Inspect live objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

3.12 traceback -- Print or retrieve a stack traceback . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

3.13 linecache -- Random access to text lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

3.14 pickle -- Python object serialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

3.15 cPickle -- Alternate implementation of pickle . . . . . . . . . . . . . . . . . . . . . . . . . . 59

3.16 copy reg -- Register pickle support functions . . . . . . . . . . . . . . . . . . . . . . . . . . 59

3.17 shelve -- Python object persistence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

3.18 copy -- Shallow and deep copy operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

3.19 marshal -- Alternate Python object serialization . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

3.20 warnings -- Warning control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62

3.21 imp -- Access the import internals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

3.22 code -- Interpreter base classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

3.23 codeop -- Compile Python code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69

3.24 pprint -- Data pretty printer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69

3.25 repr -- Alternate repr() implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71

3.26 new -- Creation of runtime internal objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

3.27 site -- Site-specific configuration hook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

3.28 user -- User-specific configuration hook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74

3.29 builtin -- Built-in functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75

3.30 main -- Top-level script environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75

i

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download