home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 5
/
DATAFILE_PDCD5.iso
/
utilities
/
p
/
python
/
!ibrowse
/
files
/
pylibi-1
(
.txt
)
< prev
next >
Wrap
GNU Info File
|
1996-11-14
|
39KB
|
785 lines
This is Info file pylibi, produced by Makeinfo-1.55 from the input file
lib.texi.
This file describes the built-in types, exceptions and functions and the
standard modules that come with the Python system. It assumes basic
knowledge about the Python language. For an informal introduction to
the language, see the Python Tutorial. The Python Reference Manual
gives a more formal definition of the language. (These manuals are not
yet available in INFO or Texinfo format.)
Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the names of Stichting Mathematisch
Centrum or CWI or Corporation for National Research Initiatives or CNRI
not be used in advertising or publicity pertaining to distribution of
the software without specific, written prior permission.
While CWI is the initial source for this software, a modified version
is made available by the Corporation for National Research Initiatives
(CNRI) at the Internet address ftp://ftp.python.org.
STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
File: pylibi, Node: Top, Next: Introduction, Prev: (dir), Up: (dir)
The Python library
******************
This file describes the built-in types, exceptions and functions and the
standard modules that come with the Python system. It assumes basic
knowledge about the Python language. For an informal introduction to
the language, see the `Python Tutorial'. The `Python Reference Manual'
gives a more formal definition of the language. (These manuals are not
yet available in INFO or Texinfo format.)
This version corresponds to Python version 1.4 (Oct 25 1996).
* Menu:
* Introduction::
* Built-in Objects::
* Python Services::
* String Services::
* Miscellaneous Services::
* Generic Operating System Services::
* Optional Operating System Services::
* The Python Debugger::
* The Python Profiler::
* Internet and WWW::
* Restricted Execution::
* Cryptographic Services::
* RISCOS ONLY::
* Function Index::
* Variable Index::
* Module Index::
* Concept Index::
File: pylibi, Node: Introduction, Next: Built-in Objects, Prev: Top, Up: Top
Introduction
************
The "Python library" contains several different kinds of components.
It contains data types that would normally be considered part of the
"core" of a language, such as numbers and lists. For these types, the
Python language core defines the form of literals and places some
constraints on their semantics, but does not fully define the
semantics. (On the other hand, the language core does define syntactic
properties like the spelling and priorities of operators.)
The library also contains built-in functions and exceptions -- objects
that can be used by all Python code without the need of an `import'
statement. Some of these are defined by the core language, but many
are not essential for the core semantics and are only described here.
The bulk of the library, however, consists of a collection of modules.
There are many ways to dissect this collection. Some modules are
written in C and built in to the Python interpreter; others are written
in Python and imported in source form. Some modules provide interfaces
that are highly specific to Python, like printing a stack trace; some
provide interfaces that are specific to particular operating systems,
like socket I/O; others provide interfaces that are specific to a
particular application domain, like the World-Wide Web. Some modules
are avaiable in all versions and ports of Python; others are only
available when the underlying system supports or requires them; yet
others are available only when a particular configuration option was
chosen at the time when Python was compiled and installed.
This manual is organized "from the inside out": it first describes the
built-in data types, then the built-in functions and exceptions, and
finally the modules, grouped in chapters of related modules. The
ordering of the chapters as well as the ordering of the modules within
each chapter is roughly from most relevant to least important.
This means that if you start reading this manual from the start, and
skip to the next chapter when you get bored, you will get a reasonable
overview of the available modules and application areas that are
supported by the Python library. Of course, you don't *have* to read
it like a novel -- you can also browse the table of contents (in front
of the manual), or look for a specific function, module or term in the
index (in the back). And finally, if you enjoy learning about random
subjects, you choose a random page number (see module `rand') and read
a section or two.
Let the show begin!
File: pylibi, Node: Built-in Objects, Next: Python Services, Prev: Introduction, Up: Top
Built-in Types, Exceptions and Functions
****************************************
Names for built-in exceptions and functions are found in a separate
symbol table. This table is searched last when the interpreter looks
up the meaning of a name, so local and global user-defined names can
override built-in names. Built-in types are described together here
for easy reference.(1)
The tables in this chapter document the priorities of operators by
listing them in order of ascending priority (within a table) and
grouping operators that have the same priority in the same box. Binary
operators of the same priority group from left to right. (Unary
operators group from right to left, but there you have no real choice.)
See Chapter 5 of the Python Reference Manual for the complete picture
on operator priorities.
* Menu:
* Types::
* Exceptions::
* Built-in Functions::
---------- Footnotes ----------
(1) Most descriptions sorely lack explanations of the exceptions that
may be raised -- this will be fixed in a future version of this manual.
File: pylibi, Node: Types, Next: Exceptions, Prev: Built-in Objects, Up: Built-in Objects
Built-in Types
==============
The following sections describe the standard types that are built into
the interpreter. These are the numeric types, sequence types, and
several others, including types themselves. There is no explicit
Boolean type; use integers instead.
Some operations are supported by several object types; in particular,
all objects can be compared, tested for truth value, and converted to a
string (with the ``...`' notation). The latter conversion is
implicitly used when an object is written by the `print' statement.
* Menu:
* Truth Value Testing::
* Boolean Operations::
* Comparisons::
* Numeric Types::
* Sequence Types::
* Mapping Types::
* Other Built-in Types::
* Special Attributes::
File: pylibi, Node: Truth Value Testing, Next: Boolean Operations, Prev: Types, Up: Types
Truth Value Testing
-------------------
Any object can be tested for truth value, for use in an `if' or `while'
condition or as operand of the Boolean operations below. The following
values are considered false:
* `None'
* zero of any numeric type, e.g., `0', `0L', `0.0'.
* any empty sequence, e.g., `''', `()', `[]'.
* any empty mapping, e.g., `{}'.
* instances of user-defined classes, if the class defines a
`__nonzero__()' or `__len__()' method, when that method returns
zero.
All other values are considered true -- so objects of many types are
always true.
Operations and built-in functions that have a Boolean result always
return `0' for false and `1' for true, unless otherwise stated.
(Important exception: the Boolean oper