Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 862c6f1

Browse files
committed
Added stuff about classes and instances, plus some smaller changes.
1 parent 9b57385 commit 862c6f1

2 files changed

Lines changed: 136 additions & 50 deletions

File tree

Doc/ref.tex

Lines changed: 68 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
% Format this file with latex.
2-
31
\documentstyle[11pt,myformat]{report}
42

5-
\title{\bf
6-
Python Reference Manual
7-
}
8-
3+
\title{\bf Python Reference Manual}
4+
95
\author{
106
Guido van Rossum \\
117
Dept. CST, CWI, Kruislaan 413 \\
@@ -487,11 +483,20 @@ \section{Execution frames, name spaces, and scopes}
487483

488484
\chapter{The standard type hierarchy}
489485

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
493489
numbers, lists of efficiently stored integers, etc.).
494490

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+
495500
\begin{description}
496501

497502
\item[None]
@@ -648,10 +653,10 @@ \chapter{The standard type hierarchy}
648653
\begin{description}
649654

650655
\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.
655660

656661
Special read-only attributes: \verb\func_code\ is the code object
657662
representing the compiled function body, and \verb\func_globals\ is (a
@@ -692,23 +697,53 @@ \chapter{The standard type hierarchy}
692697
\end{description}
693698

694699
\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
697703
\ver\func_globals\ attribute of functions defined in the module).
698704
Module attribute references are translated to lookups in this
699705
dictionary. A module object does not contain the code object used to
700706
initialize the module (since it isn't needed once the initialization
701707
is done).
702708

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.
706713

707714
\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.
709733

710734
\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.
712747

713748
\item[Files]
714749
A file object represents an open file. (It is a wrapper around a C
@@ -1587,7 +1622,7 @@ \section{The {\tt continue} statement}
15871622

15881623
It continues with the next cycle of the nearest enclosing loop.
15891624

1590-
\section{The {\tt import} statement}
1625+
\section{The {\tt import} statement} \label{import}
15911626

15921627
\begin{verbatim}
15931628
import_stmt: "import" identifier ("," identifier)*
@@ -1646,7 +1681,7 @@ \section{The {\tt import} statement}
16461681
implementations may enforce them or silently change the meaning of the
16471682
program.)
16481683

1649-
\section{The {\tt global} statement}
1684+
\section{The {\tt global} statement} \label{global}
16501685

16511686
\begin{verbatim}
16521687
global_stmt: "global" identifier ("," identifier)*
@@ -1842,23 +1877,31 @@ \section{The {\tt try} statement}
18421877
reason is a problem with the current implementation -- this
18431878
restriction may be lifted in the future).
18441879

1880+
\section{Function definitions} \label{function}
18451881

1846-
1847-
\section{Function definitions}
1882+
XXX
18481883

18491884
\begin{verbatim}
18501885
funcdef: "def" identifier "(" [parameter_list] ")" ":" suite
18511886
parameter_list: parameter ("," parameter)*
18521887
parameter: identifier | "(" parameter_list ")"
18531888
\end{verbatim}
18541889

1855-
\section{Class definitions}
1890+
XXX
1891+
1892+
\section{Class definitions} \label{class}
1893+
1894+
XXX
18561895

18571896
\begin{verbatim}
18581897
classdef: "class" identifier [inheritance] ":" suite
18591898
inheritance: "(" expression ("," expression)* ")"
18601899
\end{verbatim}
18611900

1901+
XXX
1902+
1903+
\section{P.M.}
1904+
18621905
XXX Syntax for scripts, modules
18631906
XXX Syntax for interactive input, eval, exec, input
18641907
XXX New definition of expressions (as conditions)

Doc/ref/ref.tex

Lines changed: 68 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
% Format this file with latex.
2-
31
\documentstyle[11pt,myformat]{report}
42

5-
\title{\bf
6-
Python Reference Manual
7-
}
8-
3+
\title{\bf Python Reference Manual}
4+
95
\author{
106
Guido van Rossum \\
117
Dept. CST, CWI, Kruislaan 413 \\
@@ -487,11 +483,20 @@ \section{Execution frames, name spaces, and scopes}
487483

488484
\chapter{The standard type hierarchy}
489485

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
493489
numbers, lists of efficiently stored integers, etc.).
494490

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+
495500
\begin{description}
496501

497502
\item[None]
@@ -648,10 +653,10 @@ \chapter{The standard type hierarchy}
648653
\begin{description}
649654

650655
\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.
655660

656661
Special read-only attributes: \verb\func_code\ is the code object
657662
representing the compiled function body, and \verb\func_globals\ is (a
@@ -692,23 +697,53 @@ \chapter{The standard type hierarchy}
692697
\end{description}
693698

694699
\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
697703
\ver\func_globals\ attribute of functions defined in the module).
698704
Module attribute references are translated to lookups in this
699705
dictionary. A module object does not contain the code object used to
700706
initialize the module (since it isn't needed once the initialization
701707
is done).
702708

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.
706713

707714
\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.
709733

710734
\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.
712747

713748
\item[Files]
714749
A file object represents an open file. (It is a wrapper around a C
@@ -1587,7 +1622,7 @@ \section{The {\tt continue} statement}
15871622

15881623
It continues with the next cycle of the nearest enclosing loop.
15891624

1590-
\section{The {\tt import} statement}
1625+
\section{The {\tt import} statement} \label{import}
15911626

15921627
\begin{verbatim}
15931628
import_stmt: "import" identifier ("," identifier)*
@@ -1646,7 +1681,7 @@ \section{The {\tt import} statement}
16461681
implementations may enforce them or silently change the meaning of the
16471682
program.)
16481683

1649-
\section{The {\tt global} statement}
1684+
\section{The {\tt global} statement} \label{global}
16501685

16511686
\begin{verbatim}
16521687
global_stmt: "global" identifier ("," identifier)*
@@ -1842,23 +1877,31 @@ \section{The {\tt try} statement}
18421877
reason is a problem with the current implementation -- this
18431878
restriction may be lifted in the future).
18441879

1880+
\section{Function definitions} \label{function}
18451881

1846-
1847-
\section{Function definitions}
1882+
XXX
18481883

18491884
\begin{verbatim}
18501885
funcdef: "def" identifier "(" [parameter_list] ")" ":" suite
18511886
parameter_list: parameter ("," parameter)*
18521887
parameter: identifier | "(" parameter_list ")"
18531888
\end{verbatim}
18541889

1855-
\section{Class definitions}
1890+
XXX
1891+
1892+
\section{Class definitions} \label{class}
1893+
1894+
XXX
18561895

18571896
\begin{verbatim}
18581897
classdef: "class" identifier [inheritance] ":" suite
18591898
inheritance: "(" expression ("," expression)* ")"
18601899
\end{verbatim}
18611900

1901+
XXX
1902+
1903+
\section{P.M.}
1904+
18621905
XXX Syntax for scripts, modules
18631906
XXX Syntax for interactive input, eval, exec, input
18641907
XXX New definition of expressions (as conditions)

0 commit comments

Comments
 (0)