home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 5
/
DATAFILE_PDCD5.iso
/
utilities
/
p
/
python
/
!ibrowse
/
files
/
pylibi-2
(
.txt
)
< prev
next >
Wrap
GNU Info File
|
1996-11-14
|
48KB
|
872 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: Built-in Functions, Prev: Exceptions, Up: Built-in Objects
Built-in Functions
==================
The Python interpreter has a number of functions built into it that are
always available. They are listed here in alphabetical order.
- built-in function: abs (X)
Return the absolute value of a number. The argument may be a plain
or long integer or a floating point number.
- built-in function: apply (FUNCTION, ARGS[, KEYWORDS])
The FUNCTION argument must be a callable object (a user-defined or
built-in function or method, or a class object) and the ARGS
argument must be a tuple. The FUNCTION is called with ARGS as
argument list; the number of arguments is the the length of the
tuple. (This is different from just calling `FUNC(ARGS)', since
in that case there is always exactly one argument.) If the
optional KEYWORDS argument is present, it must be a dictionary
whose keys are strings. It specifies keyword arguments to be
added to the end of the the argument list.
- built-in function: chr (I)
Return a string of one character whose ASCII code is the integer
I, e.g., `chr(97)' returns the string `'a''. This is the inverse
of `ord()'. The argument must be in the range [0..255], inclusive.
- built-in function: cmp (X, Y)
Compare the two objects X and Y and return an integer according to
the outcome. The return value is negative if `X < Y', zero if `X
== Y' and strictly positive if `X > Y'.
- built-in function: coerce (X, Y)
Return a tuple consisting of the two numeric arguments converted to
a common type, using the same rules as used by arithmetic
operations.
- built-in function: compile (STRING, FILENAME, KIND)
Compile the STRING into a code object. Code objects can be
executed by an `exec' statement or evaluated by a call to
`eval()'. The FILENAME argument should give the file from which
the code was read; pass e.g. `'<string>'' if it wasn't read from a
file. The KIND argument specifies what kind of code must be
compiled; it can be `'exec'' if STRING consists of a sequence of
statements, `'eval'' if it consists of a single expression, or
`'single'' if it consists of a single interactive statement (in
the latter case, expression statements that evaluate to something
else than `None' will printed).
- built-in function: delattr (OBJECT, NAME)
This is a relative of `setattr'. The arguments are an object and
a string. The string must be the name of one of the object's
attributes. The function deletes the named attribute, provided
the object allows it. For example, `delattr(X, 'FOOBAR')' is
equivalent to `del X.FOOBAR'.
- built-in function: dir ()
Without arguments, return the list of names in the current local
symbol table. With a module, class or class instance object as
argument (or anything else that has a `__dict__' attribute),
returns the list of names in that object's attribute dictionary.
The resulting list is sorted. For example:
>>> import sys
>>> dir()
['sys']
>>> dir(sys)
['argv', 'exit', 'modules', 'path', 'stderr', 'stdin', 'stdout']
>>>
- built-in function: divmod (A, B)
Take two numbers as arguments and return a pair of integers
consisting of their integer quotient and remainder. With mixed
operand types, the rules for binary arithmetic operators apply.
For plain and long integers, the result is the same as `(A / B, A
% B)'. For floating point numbers the result is the same as
`(math.floor(A / B), A % B)'.
- built-in function: eval (EXPRESSION[, GLOBALS[, LOCALS]])
The arguments are a string and two optional dictionaries. The
EXPRESSION argument is parsed and evaluated as a Python expression
(technically speaking, a condition list) using the GLOBALS and
LOCALS dictionaries as global and local name space. If the LOCALS
dictionary is omitted it defaults to the GLOBALS dictionary. If
both dictionaries are omitted, the expression is executed in the
environment where `eval' is called. The return value is the
result of the evaluated expression. Syntax errors are reported as
exceptions. Example:
>>> x = 1
>>> print eval('x+1')
2
>>>
This function can also be used to execute arbitrary code objects
(e.g. created by `compile()'). In this case pass a code object
instead of a string. The code object must have been compiled
passing `'eval'' to the KIND argument.
Hints: dynamic execution of statements is supported by the `exec'
statement. Execution of statements from a file is supported by
the `execfile()' function. The `globals()' and `locals()'
functions returns the current global and local dictionary,
respectively, which may be useful to pass around for use by
`eval()' or `execfile()'.
- built-in function: execfile (FILE[, GLOBALS[, LOCALS]])
This function is similar to the `exec' statement, but parses a
file instead of a string. It is different from the `import'
statement in that it does not use the module administration -- it
reads the file unconditionally and does not create a new module.(1)
The arguments are a file name and two optional dictionaries. The
file is parsed and evaluated as a sequence of Python statements
(similarly to a module) using the GLOBALS and LOCALS dictionaries
as global and local name space. If the LOCALS dictionary is
omitted it defaults to the GLOBALS dictionary. If both
dictionaries are omitted, the expression is executed in the
environment where `execfile()' is called. The return value is
`None'.
- built-in function: filter (FUNCTION, LIST)
Construct a list from those elements of LIST for which FUNCTION
returns true. If LIST is a string or a tuple, the result also has
that type; otherwise it is always a list. If FUNCTION is `None',
the identity function is assumed, i.e. all elements of LIST that
are false (zero or empty) are removed.
- built-in function: float (X)
Convert a number to floating point. The argument may be a plain or
long integer or a floating point