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 >
GNU Info File  |  1996-11-14  |  48KB  |  872 lines

  1. This is Info file pylibi, produced by Makeinfo-1.55 from the input file
  2. lib.texi.
  3. This file describes the built-in types, exceptions and functions and the
  4. standard modules that come with the Python system.  It assumes basic
  5. knowledge about the Python language.  For an informal introduction to
  6. the language, see the Python Tutorial.  The Python Reference Manual
  7. gives a more formal definition of the language.  (These manuals are not
  8. yet available in INFO or Texinfo format.)
  9. Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, The
  10. Netherlands.
  11. All Rights Reserved
  12. Permission to use, copy, modify, and distribute this software and its
  13. documentation for any purpose and without fee is hereby granted,
  14. provided that the above copyright notice appear in all copies and that
  15. both that copyright notice and this permission notice appear in
  16. supporting documentation, and that the names of Stichting Mathematisch
  17. Centrum or CWI or Corporation for National Research Initiatives or CNRI
  18. not be used in advertising or publicity pertaining to distribution of
  19. the software without specific, written prior permission.
  20. While CWI is the initial source for this software, a modified version
  21. is made available by the Corporation for National Research Initiatives
  22. (CNRI) at the Internet address ftp://ftp.python.org.
  23. STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
  24. REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
  25. MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
  26. CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
  27. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  28. PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  29. ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
  30. THIS SOFTWARE.
  31. File: pylibi,  Node: Built-in Functions,  Prev: Exceptions,  Up: Built-in Objects
  32. Built-in Functions
  33. ==================
  34. The Python interpreter has a number of functions built into it that are
  35. always available.  They are listed here in alphabetical order.
  36.  - built-in function: abs (X)
  37.      Return the absolute value of a number.  The argument may be a plain
  38.      or long integer or a floating point number.
  39.  - built-in function: apply (FUNCTION, ARGS[, KEYWORDS])
  40.      The FUNCTION argument must be a callable object (a user-defined or
  41.      built-in function or method, or a class object) and the ARGS
  42.      argument must be a tuple.  The FUNCTION is called with ARGS as
  43.      argument list; the number of arguments is the the length of the
  44.      tuple.  (This is different from just calling `FUNC(ARGS)', since
  45.      in that case there is always exactly one argument.) If the
  46.      optional KEYWORDS argument is present, it must be a dictionary
  47.      whose keys are strings.  It specifies keyword arguments to be
  48.      added to the end of the the argument list.
  49.  - built-in function: chr (I)
  50.      Return a string of one character whose ASCII code is the integer
  51.      I, e.g., `chr(97)' returns the string `'a''.  This is the inverse
  52.      of `ord()'.  The argument must be in the range [0..255], inclusive.
  53.  - built-in function: cmp (X, Y)
  54.      Compare the two objects X and Y and return an integer according to
  55.      the outcome.  The return value is negative if `X < Y', zero if `X
  56.      == Y' and strictly positive if `X > Y'.
  57.  - built-in function: coerce (X, Y)
  58.      Return a tuple consisting of the two numeric arguments converted to
  59.      a common type, using the same rules as used by arithmetic
  60.      operations.
  61.  - built-in function: compile (STRING, FILENAME, KIND)
  62.      Compile the STRING into a code object.  Code objects can be
  63.      executed by an `exec' statement or evaluated by a call to
  64.      `eval()'.  The FILENAME argument should give the file from which
  65.      the code was read; pass e.g. `'<string>'' if it wasn't read from a
  66.      file.  The KIND argument specifies what kind of code must be
  67.      compiled; it can be `'exec'' if STRING consists of a sequence of
  68.      statements, `'eval'' if it consists of a single expression, or
  69.      `'single'' if it consists of a single interactive statement (in
  70.      the latter case, expression statements that evaluate to something
  71.      else than `None' will printed).
  72.  - built-in function: delattr (OBJECT, NAME)
  73.      This is a relative of `setattr'.  The arguments are an object and
  74.      a string.  The string must be the name of one of the object's
  75.      attributes.  The function deletes the named attribute, provided
  76.      the object allows it.  For example, `delattr(X, 'FOOBAR')' is
  77.      equivalent to `del X.FOOBAR'.
  78.  - built-in function: dir ()
  79.      Without arguments, return the list of names in the current local
  80.      symbol table.  With a module, class or class instance object as
  81.      argument (or anything else that has a `__dict__' attribute),
  82.      returns the list of names in that object's attribute dictionary.
  83.      The resulting list is sorted.  For example:
  84.           >>> import sys
  85.           >>> dir()
  86.           ['sys']
  87.           >>> dir(sys)
  88.           ['argv', 'exit', 'modules', 'path', 'stderr', 'stdin', 'stdout']
  89.           >>>
  90.  - built-in function: divmod (A, B)
  91.      Take two numbers as arguments and return a pair of integers
  92.      consisting of their integer quotient and remainder.  With mixed
  93.      operand types, the rules for binary arithmetic operators apply.
  94.      For plain and long integers, the result is the same as `(A / B, A
  95.      % B)'.  For floating point numbers the result is the same as
  96.      `(math.floor(A / B), A % B)'.
  97.  - built-in function: eval (EXPRESSION[, GLOBALS[, LOCALS]])
  98.      The arguments are a string and two optional dictionaries.  The
  99.      EXPRESSION argument is parsed and evaluated as a Python expression
  100.      (technically speaking, a condition list) using the GLOBALS and
  101.      LOCALS dictionaries as global and local name space.  If the LOCALS
  102.      dictionary is omitted it defaults to the GLOBALS dictionary.  If
  103.      both dictionaries are omitted, the expression is executed in the
  104.      environment where `eval' is called.  The return value is the
  105.      result of the evaluated expression.  Syntax errors are reported as
  106.      exceptions.  Example:
  107.           >>> x = 1
  108.           >>> print eval('x+1')
  109.           2
  110.           >>>
  111.      This function can also be used to execute arbitrary code objects
  112.      (e.g. created by `compile()').  In this case pass a code object
  113.      instead of a string.  The code object must have been compiled
  114.      passing `'eval'' to the KIND argument.
  115.      Hints: dynamic execution of statements is supported by the `exec'
  116.      statement.  Execution of statements from a file is supported by
  117.      the `execfile()' function.  The `globals()' and `locals()'
  118.      functions returns the current global and local dictionary,
  119.      respectively, which may be useful to pass around for use by
  120.      `eval()' or `execfile()'.
  121.  - built-in function: execfile (FILE[, GLOBALS[, LOCALS]])
  122.      This function is similar to the `exec' statement, but parses a
  123.      file instead of a string.  It is different from the `import'
  124.      statement in that it does not use the module administration -- it
  125.      reads the file unconditionally and does not create a new module.(1)
  126.      The arguments are a file name and two optional dictionaries.  The
  127.      file is parsed and evaluated as a sequence of Python statements
  128.      (similarly to a module) using the GLOBALS and LOCALS dictionaries
  129.      as global and local name space.  If the LOCALS dictionary is
  130.      omitted it defaults to the GLOBALS dictionary.  If both
  131.      dictionaries are omitted, the expression is executed in the
  132.      environment where `execfile()' is called.  The return value is
  133.      `None'.
  134.  - built-in function: filter (FUNCTION, LIST)
  135.      Construct a list from those elements of LIST for which FUNCTION
  136.      returns true.  If LIST is a string or a tuple, the result also has
  137.      that type; otherwise it is always a list.  If FUNCTION is `None',
  138.      the identity function is assumed, i.e. all elements of LIST that
  139.      are false (zero or empty) are removed.
  140.  - built-in function: float (X)
  141.      Convert a number to floating point.  The argument may be a plain or
  142.      long integer or a floating point