8000 #1211, #1212, #1213: py3k fixes to the tutorial. · python/cpython@2d2590d · GitHub
[go: up one dir, main page]

Skip to content

Commit 2d2590d

Browse files
committed
#1211, #1212, #1213: py3k fixes to the tutorial.
1 parent 7c77f75 commit 2d2590d

File tree

4 files changed

+43
-48
lines changed

4 files changed

+43
-48
lines changed

Doc/ACKS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ docs@python.org), and we'll be glad to correct the problem.
6565
* Harald Hanche-Olsen
6666
* Manus Hand
6767
* Gerhard Häring
68+
* Peter Harris
6869
* Travis B. Hartwell
6970
* Tim Hatch
7071
* Janko Hauser

Doc/tutorial/classes.rst

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,8 @@ scope.)
473473
Multiple Inheritance
474474
--------------------
475475

476-
Python supports a limited form of multiple inheritance as well. 10000 A class
477-
definition with multiple base classes looks like this::
476+
Python supports a form of multiple inheritance as well. A class definition with
477+
multiple base classes looks like this::
478478

479479
class DerivedClassName(Base1, Base2, Base3):
480480
<statement-1>
@@ -483,15 +483,18 @@ definition with multiple base classes looks like this::
483483
.
484484
<statement-N>
485485

486-
Formerly, the only rule was depth-first, left-to-right. Thus, if an attribute
487-
was not found in :class:`DerivedClassName`, it was searched in :class:`Base1`,
488-
then (recursively) in the base classes of :class:`Base1`, and only if it was not
489-
found there, it was searched in :class:`Base2`, and so on.
490-
491-
In the meantime, the method resolution order changes dynamically to support
492-
cooperative calls to :func:`super`. This approach is known in some other
493-
multiple-inheritance languages as call-next-method and is more powerful than the
494-
super call found in single-inheritance languages.
486+
For most purposes, in the simplest cases, you can think of the search for
487+
attributes inherited from a parent class as depth-first, left-to-right, not
488+
searching twice in the same class where there is an overlap in the hierarchy.
489+
Thus, if an attribute is not found in :class:`DerivedClassName`, it is searched
490+
for in :class:`Base1`, then (recursively) in the base classes of :class:`Base1`,
491+
and if it was not found there, it was searched for in :class:`Base2`, and so on.
492+
493+
In fact, it is slightly more complex than that; the method resolution order
494+
changes dynamically to support cooperative calls to :func:`super`. This
495+
approach is known in some other multiple-inheritance languages as
496+
call-next-method and is more powerful than the super call found in
497+
single-inheritance languages.
495498

496499
Dynamic ordering is necessary because all cases of multiple inheritance exhibit
497500
one or more diamond relationships (where one at least one of the parent classes

Doc/tutorial/interpreter.rst

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,14 @@ with the *secondary prompt*, by default three dots (``...``). The interpreter
101101
prints a welcome message stating its version number and a copyright notice
102102
before printing the first prompt::
103103

104-
python
105-
Python 1.5.2b2 (#1, Feb 28 1999, 00:02:06) [GCC 2.8.1] on sunos5
106-
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
104+
$ python
105+
Python 3.0a1 (py3k, Sep 12 2007, 12:21:02)
106+
[GCC 3.4.6 20060404 (Red Hat 3.4.6-8)] on linux2
107+
Type "help", "copyright", "credits" or "license" for more information.
107108
>>>
108109

110+
.. XXX update for final release of Python 3.0
111+
109112
Continuation lines are needed when entering a multi-line construct. As an
110113
example, take a look at this :keyword:`if` statement::
111114

@@ -170,44 +173,32 @@ The script can be given an executable mode, or permission, using the
170173
Source Code Encoding
171174
--------------------
172175

173-
.. XXX out of date!
176+
By default, Python source files are treated as encoded in UTF-8. In that
177+
encoding, characters of most languages in the world can be used simultaneously
178+
in string literals, identifiers and comments --- although the standard library
179+
only uses ASCII characters for identifiers, a convention that any portable code
180+
should follow. To display all these characters properly, your editor must
181+
recognize that the file is UTF-8, and it must use a font that supports all the
182+
characters in the file.
174183

175-
It is possible to use encodings different than ASCII in Python source files. The
176-
best way to do it is to put one more special comment line right after the ``#!``
177-
line to define the source file encoding::
184+
It is also possible to specify a different encoding for source files. In order
185+
to do this, put one more special comment line right after the ``#!`` line to
186+
define the source file encoding::
178187

179188
# -*- coding: encoding -*-
180189

190+
With that declaration, everything in the source file will be treated as having
191+
the encoding *encoding* instead of UTF-8. The list of possible encodings can be
192+
found in the Python Library Reference, in the section on :mod:`codecs`.
181193

182-
With that declaration, all characters in the source file will be treated as
183-
having the encoding *encoding*, and it will be possible to directly write
184-
Unicode string literals in the selected encoding. The list of possible
185-
encodings can be found in the Python Library Reference, in the section on
186-
:mod:`codecs`.
187-
188-
For example, to write Unicode literals including the Euro currency symbol, the
189-
ISO-8859-15 encoding can be used, with the Euro symbol having the ordinal value
190-
164. This script will print the value 8364 (the Unicode codepoint corresponding
191-
to the Euro symbol) and then exit::
192-
193-
# -*- coding: iso-8859-15 -*-
194-
195-
currency = u"€"
196-
print(ord(currency))
194+
For example, if your editor of choice does not support UTF-8 encoded files and
195+
insists on using some other encoding, say Windows-1252, you can write::
197196

198-
If your editor supports saving files as ``UTF-8`` with a UTF-8 *byte order mark*
199-
(aka BOM), you can use that instead of an encoding declaration. IDLE supports
200-
this capability if ``Options/General/Default Source Encoding/UTF-8`` is set.
201-
Notice that this signature is not understood in older Python releases (2.2 and
202-
earlier), and also not understood by the operating system for script files with
203-
``#!`` lines (only used on Unix systems).
197+
# -*- coding: cp-1252 -*-
204198

205-
By using UTF-8 (either through the signature or an encoding declaration),
206-
characters of most languages in the world can be used simultaneously in string
207-
literals and comments. Using non-ASCII characters in identifiers is not
208-
supported. To display all these characters properly, your editor must recognize
209-
that the file is UTF-8, and it must use a font that supports all the characters
210-
in the file.
199+
and still use all characters in the Windows-1252 character set in the source
200+
files. The special encoding comment must be in the *first or second* line
201+
within the file.
211202

212203

213204
.. _tut-startup:

Doc/tutorial/introduction.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ and imaginary part. To extract these parts from a complex number *z*, use
131131
0.5
132132

133133
The conversion functions to floating point and integer (:func:`float`,
134-
:func:`int` and :func:`long`) don't work for complex numbers --- there is no one
135-
correct way to convert a complex number to a real number. Use ``abs(z)`` to get
136-
its magnitude (as a float) or ``z.real`` to get its real part. ::
134+
:func:`int`) don't work for complex numbers --- there is not one correct way to
135+
convert a complex number to a real number. Use ``abs(z)`` to get its magnitude
136+
(as a float) or ``z.real`` to get its real part::
137137

138138
>>> a=3.0+4.0j
139139
>>> float(a)

0 commit comments

Comments
 (0)
0