|
1 | | -% Format this file with latex. |
2 | | - |
3 | 1 | \documentstyle[11pt,myformat]{report} |
4 | 2 |
|
5 | | -\title{\bf |
6 | | - Python Reference Manual |
7 | | -} |
8 | | - |
| 3 | +\title{\bf Python Reference Manual} |
| 4 | + |
9 | 5 | \author{ |
10 | 6 | Guido van Rossum \\ |
11 | 7 | Dept. CST, CWI, Kruislaan 413 \\ |
@@ -487,11 +483,20 @@ \section{Execution frames, name spaces, and scopes} |
487 | 483 |
|
488 | 484 | \chapter{The standard type hierarchy} |
489 | 485 |
|
490 | | -The following types are built into Python. Extension modules |
491 | | -written in C can define additional types. Future versions of Python |
492 | | -may also add types to the type hierarchy (e.g., rational or complex |
| 486 | +Below is a list of the types that are built into Python. Extension |
| 487 | +modules written in C can define additional types. Future versions of |
| 488 | +Python may add types to the type hierarchy (e.g., rational or complex |
493 | 489 | numbers, lists of efficiently stored integers, etc.). |
494 | 490 |
|
| 491 | +Some type descriptions contain a paragraph listing `special |
| 492 | +attributes'. These are attributes that provide access to the |
| 493 | +implementation and are not intended for general use. Their definition |
| 494 | +may change in the future. There are also some `generic' special |
| 495 | +attributes, not listed with the individual objects: \verb\__methods__\ |
| 496 | +is a list of the method names of a built-in object, if it has any; |
| 497 | +\verb\__members__\ is a list of the data attribute names of a built-in |
| 498 | +object, if it has any. |
| 499 | + |
495 | 500 | \begin{description} |
496 | 501 |
|
497 | 502 | \item[None] |
@@ -648,10 +653,10 @@ \chapter{The standard type hierarchy} |
648 | 653 | \begin{description} |
649 | 654 |
|
650 | 655 | \item[User-defined functions] |
651 | | -A user-defined function is created by a function definition (starting |
652 | | -with the \verb\def\ keyword). It should be called with an argument |
653 | | -list containing the same number of items as the function's |
654 | | -formal parameter list. |
| 656 | +A user-defined function is created by a function definition (see |
| 657 | +section \ref{function}). It should be called with an argument list |
| 658 | +containing the same number of items as the function's formal parameter |
| 659 | +list. |
655 | 660 |
|
656 | 661 | Special read-only attributes: \verb\func_code\ is the code object |
657 | 662 | representing the compiled function body, and \verb\func_globals\ is (a |
@@ -692,23 +697,53 @@ \chapter{The standard type hierarchy} |
692 | 697 | \end{description} |
693 | 698 |
|
694 | 699 | \item[Modules] |
695 | | -A module object is a container for a module's name space, which is a |
696 | | -dictionary (the same dictionary as referenced by the |
| 700 | +Modules are imported by the \verb\import\ statement (see section |
| 701 | +\ref{import}). A module object is a container for a module's name |
| 702 | +space, which is a dictionary (the same dictionary as referenced by the |
697 | 703 | \ver\func_globals\ attribute of functions defined in the module). |
698 | 704 | Module attribute references are translated to lookups in this |
699 | 705 | dictionary. A module object does not contain the code object used to |
700 | 706 | initialize the module (since it isn't needed once the initialization |
701 | 707 | is done). |
702 | 708 |
|
703 | | -There are two special read-only attributes: \verb\__dict__\ yields the |
704 | | -module's name space as a dictionary object; \verb\__name__\ yields the |
705 | | -module's name. |
| 709 | +Attribute assignment update the module's name space dictionary. |
| 710 | + |
| 711 | +Special read-only attributes: \verb\__dict__\ yields the module's name |
| 712 | +space as a dictionary object; \verb\__name__\ yields the module's name. |
706 | 713 |
|
707 | 714 | \item[Classes] |
708 | | -XXX |
| 715 | +Class objects are created by class definitions (see section |
| 716 | +\ref{class}). A class is a container for a dictionary containing the |
| 717 | +class's name space. Class attribute references are translated to |
| 718 | +lookups in this dictionary. When an attribute name is not found |
| 719 | +there, the attribute search continues in the base classes. The search |
| 720 | +is depth-first, left-to-right in the order of their occurrence in the |
| 721 | +base class list. |
| 722 | + |
| 723 | +Attribute assignments update the class's dictionary, never the |
| 724 | +dictionary of a base class. |
| 725 | + |
| 726 | +A class can be called as a parameterless function to yield a class |
| 727 | +instance (see above). |
| 728 | + |
| 729 | +Special read-only attributes: \verb\__dict__\ yields te dictionary |
| 730 | +containing the class's name space; \verb\__bases__\ yields a tuple |
| 731 | +(possibly empty or a singleton) containing the base classes, in the |
| 732 | +order of their occurrence in the base class list. |
709 | 733 |
|
710 | 734 | \item[Class instances] |
711 | | -XXX |
| 735 | +A class instance is created by calling a class object as a |
| 736 | +parameterless function. A class instance has a dictionary in which |
| 737 | +attribute references are searched. When an attribute is not found |
| 738 | +there, and the instance's class has an attribute by that name, and |
| 739 | +that class attribute is a user-defined function (and in no other |
| 740 | +cases), the instance attribute reference yields a user-defined method |
| 741 | +object (see above) constructed from the instance and the function. |
| 742 | + |
| 743 | +Attribute assignments update the instance's dictionary. |
| 744 | + |
| 745 | +Special read-only attributes: \verb\__dict__\ yields the attribute |
| 746 | +dictionary; \verb\__class__\ yields the instance's class. |
712 | 747 |
|
713 | 748 | \item[Files] |
714 | 749 | A file object represents an open file. (It is a wrapper around a C |
@@ -1587,7 +1622,7 @@ \section{The {\tt continue} statement} |
1587 | 1622 |
|
1588 | 1623 | It continues with the next cycle of the nearest enclosing loop. |
1589 | 1624 |
|
1590 | | -\section{The {\tt import} statement} |
| 1625 | +\section{The {\tt import} statement} \label{import} |
1591 | 1626 |
|
1592 | 1627 | \begin{verbatim} |
1593 | 1628 | import_stmt: "import" identifier ("," identifier)* |
@@ -1646,7 +1681,7 @@ \section{The {\tt import} statement} |
1646 | 1681 | implementations may enforce them or silently change the meaning of the |
1647 | 1682 | program.) |
1648 | 1683 |
|
1649 | | -\section{The {\tt global} statement} |
| 1684 | +\section{The {\tt global} statement} \label{global} |
1650 | 1685 |
|
1651 | 1686 | \begin{verbatim} |
1652 | 1687 | global_stmt: "global" identifier ("," identifier)* |
@@ -1842,23 +1877,31 @@ \section{The {\tt try} statement} |
1842 | 1877 | reason is a problem with the current implementation -- this |
1843 | 1878 | restriction may be lifted in the future). |
1844 | 1879 |
|
| 1880 | +\section{Function definitions} \label{function} |
1845 | 1881 |
|
1846 | | - |
1847 | | -\section{Function definitions} |
| 1882 | +XXX |
1848 | 1883 |
|
1849 | 1884 | \begin{verbatim} |
1850 | 1885 | funcdef: "def" identifier "(" [parameter_list] ")" ":" suite |
1851 | 1886 | parameter_list: parameter ("," parameter)* |
1852 | 1887 | parameter: identifier | "(" parameter_list ")" |
1853 | 1888 | \end{verbatim} |
1854 | 1889 |
|
1855 | | -\section{Class definitions} |
| 1890 | +XXX |
| 1891 | + |
| 1892 | +\section{Class definitions} \label{class} |
| 1893 | + |
| 1894 | +XXX |
1856 | 1895 |
|
1857 | 1896 | \begin{verbatim} |
1858 | 1897 | classdef: "class" identifier [inheritance] ":" suite |
1859 | 1898 | inheritance: "(" expression ("," expression)* ")" |
1860 | 1899 | \end{verbatim} |
1861 | 1900 |
|
| 1901 | +XXX |
| 1902 | + |
| 1903 | +\section{P.M.} |
| 1904 | + |
1862 | 1905 | XXX Syntax for scripts, modules |
1863 | 1906 | XXX Syntax for interactive input, eval, exec, input |
1864 | 1907 | XXX New definition of expressions (as conditions) |
|
0 commit comments