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

Skip to content

Commit 3a26dd8

Browse files
committed
Done with the "New in 1.4" chapter.
1 parent b0259bc commit 3a26dd8

2 files changed

Lines changed: 280 additions & 152 deletions

File tree

Doc/tut.tex

Lines changed: 140 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
window managers.
2929

3030
Python is available for various operating systems, amongst which
31-
several flavors of {\UNIX}, Amoeba, the Apple Macintosh O.S.,
32-
and MS-DOS.
31+
several flavors of {\UNIX}, the Apple Macintosh, MS-DOS, Windows
32+
(3.1(1), '95 and NT flavors), OS/2, and others.
3333

3434
This tutorial introduces the reader informally to the basic concepts
3535
and features of the Python language and system. It helps to have a
@@ -55,6 +55,23 @@
5555

5656
\chapter{Whetting Your Appetite}
5757

58+
\section{Disclaimer}
59+
60+
Now that there are several books out on Python, this tutorial has lost
61+
its role as the only introduction to Python for most new users. It
62+
takes time to keep a document like this up to date in the face of
63+
additions to the language, and I simply don't have enough time to do a
64+
good job. Therefore, this version of the tutorial is almost unchanged
65+
since the previous release. This doesn't mean that the tutorial is
66+
out of date --- all the examples still work exactly as before. There
67+
are simply some new areas of the language that aren't covered.
68+
69+
To make up for this, there are some chapters at the end cover
70+
important changes in recent Python releases, and these are up to date
71+
with the current release.
72+
73+
\section{Introduction}
74+
5875
If you ever wrote a large shell script, you probably know this
5976
feeling: you'd love to add yet another feature, but it's already so
6077
slow, and so big, and so complicated; or the feature involves a system
@@ -2620,7 +2637,7 @@ \section{Odds and ends}
26202637
function object corresponding to the method.
26212638

26222639

2623-
\chapter{Recent Additions}
2640+
\chapter{Recent Additions as of Release 1.1}
26242641

26252642
Python is an evolving language. Since this tutorial was last
26262643
thoroughly revised, several new features have been added to the
@@ -3879,6 +3896,8 @@ \chapter{New in Release 1.4}
38793896
process are not described in this chapter (the new installation
38803897
lay-out is explained below under \code{sys.prefix} though).
38813898

3899+
\section{Language Changes}
3900+
38823901
\begin{itemize}
38833902

38843903
\item
@@ -3941,7 +3960,7 @@ \chapter{New in Release 1.4}
39413960
\begin{verbatim}
39423961
x[0:10:2] -> slice(0, 10, 2)
39433962
x[:2:] -> slice(None, 2, None)
3944-
x[::-1] -> slice(None, None, -1)
3963+
x[::-1] -> slice(None, None, -1)
39453964
x[::] -> slice(None, None, None)
39463965
x[1, 2:3] -> (1, slice(2, 3, None))
39473966
x[1:2, 3:4] -> (slice(1, 2, None), slice(3, 4, None))
@@ -3956,7 +3975,8 @@ \chapter{New in Release 1.4}
39563975
longer a reserved word. This saves a few cycles here and there.
39573976

39583977
\item
3959-
Name mangling. There is now limited support for class-private
3978+
Private variables through name mangling.
3979+
There is now limited support for class-private
39603980
identifiers. Any identifier of the form \code{__spam} (at least two
39613981
leading underscores, at most one trailing underscore) is now textually
39623982
replaced with \code{_classname__spam}, where \code{classname} is the
@@ -3976,9 +3996,9 @@ \chapter{New in Release 1.4}
39763996
rules are designed mostly to avoid accidents; it still is possible for
39773997
a determined soul to access or modify a variable that is considered
39783998
private. This can even be useful, e.g. for the debugger, and that's
3979-
one reason why this loophole is not closed. (Buglet: accidental
3980-
derivation of a class with the same name as the base class makes
3981-
accidental use of private variables of the base class possible.)
3999+
one reason why this loophole is not closed. (Buglet: derivation of a
4000+
class with the same name as the base class makes use of private
4001+
variables of the base class possible.)
39824002

39834003
Notice that code passed to \code{exec}, \code{eval()} or
39844004
\code{evalfile()} does not consider the classname of the invoking
@@ -4008,6 +4028,31 @@ \chapter{New in Release 1.4}
40084028
self.__vdict[name] = value
40094029
\end{verbatim}
40104030

4031+
{\em Warning: this is an experimental feature.} To avoid all
4032+
potential problems, refrain from using identifiers starting with
4033+
double underscore except for predefined uses like \code{__init__}. To
4034+
use private names while maintaining future compatibility: refrain from
4035+
using the same private name in classes related via subclassing; avoid
4036+
explicit (manual) mangling/unmangling; and assume that at some point
4037+
in the future, leading double underscore will revert to being just a
4038+
naming convention. Discussion on extensive compile-time declarations
4039+
are currently underway, and it is impossible to predict what solution
4040+
will eventually be chosen for private names. Double leading
4041+
underscore is still a candidate, of course --- just not the only one.
4042+
It is placed in the distribution in the belief that it is useful, and
4043+
so that widespread experience with its use can be gained. It will not
4044+
be removed without providing a better solution and a migration path.
4045+
4046+
\end{itemize}
4047+
4048+
\section{Run-time Changes}
4049+
4050+
\begin{itemize}
4051+
4052+
\item
4053+
New built-in function \code{list()} converts any sequence to a new list.
4054+
Note that when the argument is a list, the return value is a fresh
4055+
copy, similar to what would be returned by \code{a[:]}.
40114056

40124057
\item
40134058
Improved syntax error message. Syntax errors detected by the code
@@ -4026,17 +4071,27 @@ \chapter{New in Release 1.4}
40264071
raises an exception, a warning is written to \code{sys.stderr} and the
40274072
exception is ignored. Formerly, such exceptions were ignored without
40284073
warning. (Propagating the exception is not an option since it it is
4029-
invoked from an object finalizer, which cannot
4030-
) (Buglet: The new behavior, while needed in order to debug failing
4031-
\code{__del__} methods, is occasionally annoying, because if affects
4032-
the program's standard error stream. It honors assignments to
4033-
\code{sys.stderr}, so it can be redirected from within a program if
4034-
desired.)
4074+
invoked from an object finalizer, which cannot return any kind of
4075+
status or error.) (Buglet: The new behavior, while needed in order to
4076+
debug failing \code{__del__} methods, is occasionally annoying,
4077+
because if affects the program's standard error stream. It honors
4078+
assignments to \code{sys.stderr}, so it can be redirected from within
4079+
a program if desired.)
40354080

40364081
\item
4037-
New built-in function \code{list()} converts any sequence to a new list.
4038-
Note that when the argument is a list, the return value is a fresh
4039-
copy, similar to what would be returned by \code{a[:]}.
4082+
You can now discover from which file (if any) a module was loaded by
4083+
inspecting its \code{__file__} attribute. This attribute is not
4084+
present for built-in or frozen modules. It points to the shared
4085+
library file for dynamically loaded modules. (Buglet: this may be a
4086+
relative path and is stored in the \code{.pyc} file on compilation.
4087+
If you manipulate the current directory with \code{os.chdir()} or move
4088+
\code{.pyc} files around, the value may be incorrect.)
4089+
4090+
\end{itemize}
4091+
4092+
\section{New or Updated Modules}
4093+
4094+
\begin{itemize}
40404095

40414096
\item
40424097
New built-in module \code{operator}. While undocumented, the concept
@@ -4084,91 +4139,100 @@ \chapter{New in Release 1.4}
40844139

40854140
\item
40864141
Module files \code{pdb.py} and \code{profile.py} can now be invoked as
4087-
scripts to debug c.q. profile other scripts easily.
4142+
scripts to debug c.q. profile other scripts easily. For example:
4143+
\code{python /usr/local/lib/python1.4/profile.py myscript.py}
40884144

40894145
\item
4090-
The \code{os} module now supports the \code{putenv()} function on
4091-
systems where it is provided in the C library (Windows NT and most
4092-
Unix versions). The call \code{os.putenv('PATH', '/bin:/usr/bin')}
4093-
sets the environment variable \code{PATH} to the string
4094-
\code{'/bin:/usr/bin'}. Such changes to the environment affect
4095-
subprocesses started with \code{os.system()}, \code{os.popen()} or
4096-
\code{os.fork()} and \code{os.execv()}. When \code{putenv()} is
4097-
supported, assignments to items in \code{os.environ} are automatically
4098-
translated into corresponding calls to \code{os.putenv()}; however,
4099-
calls to \code{os.putenv()} don't update \code{os.environ}, so it is
4100-
actually preferable to assign to items of \code{os.environ}. For this
4101-
purpose, the type of \code{os.environ} is changed to a subclass of
4102-
\code{UserDict.UserDict} when \code{os.putenv()} is supported.
4103-
(Buglet: \code{os.execve()} still requires a real dictionary.)
4146+
The \code{os} module now supports the \code{putenv()} function on
4147+
systems where it is provided in the C library (Windows NT and most
4148+
Unix versions). For example, \code{os.putenv('PATH',
4149+
'/bin:/usr/bin')} sets the environment variable \code{PATH} to the
4150+
string \code{'/bin:/usr/bin'}. Such changes to the environment affect
4151+
subprocesses started with \code{os.system()}, \code{os.popen()} or
4152+
\code{os.fork()} and \code{os.execv()}. When \code{putenv()} is
4153+
supported, assignments to items in \code{os.environ} are automatically
4154+
translated into corresponding calls to \code{os.putenv()}; however,
4155+
calls to \code{os.putenv()} don't update \code{os.environ}, so it is
4156+
actually preferable to assign to items of \code{os.environ}. For this
4157+
purpose, the type of \code{os.environ} is changed to a subclass of
4158+
\code{UserDict.UserDict} when \code{os.putenv()} is supported.
4159+
(Buglet: \code{os.execve()} still requires a real dictionary, so it
4160+
won't accept \code{os.environ} as its third argument. However, you
4161+
can now use \code{os.execv()} and it will use your changes to
4162+
\code{os.environ}!.)
41044163

41054164
\item
4106-
New functions in the os module: mkfifo, plock, remove (== unlink),
4107-
and ftruncate. More functions are also available under NT. XXX
4165+
More new functions in the \code{os} module: \code{mkfifo},
4166+
\code{plock}, \code{remove} (== \code{unlink}), and \code{ftruncate}.
4167+
See the Unix manual (section 2, system calls) for these function.
4168+
More functions are also available under NT.
41084169

41094170
\item
41104171
New functions in the fcntl module: \code{lockf()} and \code{flock()}
41114172
(don't ask \code{:-)}). See the Library Reference Manual.
41124173

41134174
\item
4114-
The first item of the module search path, \code{sys.path}, is the
4175+
The first item of the module search path, \code{sys.path[0]}, is the
41154176
directory containing the script that was used to invoke the Python
41164177
interpreter. If the script directory is not available (e.g. if the
41174178
interpreter is invoked interactively or if the script is read from
41184179
standard input), \code{sys.path[0]} is the empty string, which directs
41194180
Python to search modules in the current directory first. Notice that
41204181
the script directory is inserted {\em before} the entries inserted as
41214182
a result of \code{\$PYTHONPATH}. There is no longer an entry for the
4122-
current directory later in the path (unless explicitly set by
4123-
\code{\$PYTHONPATH}).
4183+
current directory later in the path (unless explicitly set in
4184+
\code{\$PYTHONPATH} or overridden at build time).
41244185

4125-
\item
4126-
Some more configuration information is now available to Python
4127-
programs. The variable \code{sys.prefix} gives the site-specific
4128-
directory prefix where the platform independent Python files are
4129-
installed; by default, this is the string \code{"/usr/local"}. The
4130-
main collection of Python library modules is installed in the
4131-
directory \code{sys.prefix+"/lib/python"+sys.version[:3]} while the
4132-
platform independent header files (all except \code{config.h}) are
4133-
stored in \code{sys.prefix+"/include/python"+sys.version[:3]}.
4134-
4135-
Similarly, the variable \code{sys.exec_prefix} gives the site-specific
4136-
directory prefix where the platform {\em de}pendent Python files are
4137-
installed; by default, this is also \code{"/usr/local"}.
4138-
Specifically, all configuration files (e.g. the \code{config.h}
4139-
header file) are installed in the directory
4140-
\code{sys.exec_prefix+"/lib/python"+sys.version[:3]+"/config"},
4141-
and shared library modules are installed in
4142-
\code{sys.exec_prefix+"/lib/python"+sys.version[:3]+"/sharedmodules"}.
4186+
\end{itemize}
41434187

4144-
On non-Unix systems, these variables are meaningless.
4188+
\section{Configuration and Installation}
4189+
4190+
\begin{itemize}
41454191

41464192
\item
4147-
You can now discover from which file (if any) a module was loaded by
4148-
inspecting its \code{__file__} attribute. This attribute is not
4149-
present for built-in or frozen modules. It points to the shared
4150-
library file for dynamically loaded modules. (Buglet: this may be a
4151-
relative path and is stored in the \code{.pyc} file on compilation.
4152-
If you manipulate the current directory with \code{os.chdir()} or move
4153-
\code{.pyc} files around, the value may be incorrect.)
4193+
More configuration information is now available to Python programs.
4194+
The variable \code{sys.prefix} gives the site-specific directory
4195+
prefix where the platform independent Python files are installed; by
4196+
default, this is the string \code{"/usr/local"}. This can be set at
4197+
build time with the \code{--prefix} argument to the \code{configure}
4198+
script. The main collection of Python library modules is installed in
4199+
the directory \code{sys.prefix+"/lib/python1.4"} while the platform
4200+
independent header files (all except \code{config.h}) are stored in
4201+
\code{sys.prefix+"/include/python1.4"}.
4202+
4203+
Similarly, the variable \code{sys.exec_prefix} gives the site-specific
4204+
directory prefix where the platform {\em de}pendent Python files are
4205+
installed; by default, this is also \code{"/usr/local"}. This can be
4206+
set at build time with the \code{--exec-prefix} argument to the
4207+
\code{configure} script. Specifically, all configuration files
4208+
(e.g. the \code{config.h} header file) are installed in the directory
4209+
\code{sys.exec_prefix+"/lib/python1.4/config"}, and shared library
4210+
modules are installed in
4211+
\code{sys.exec_prefix+"/lib/python1.4/sharedmodules"}.
4212+
4213+
Include files are at \code{sys.prefix+"/include/python1.4"}.
4214+
4215+
It is not yet decided what the most portable way is to come up with
4216+
the version number used in these pathnames. For compatibility with
4217+
the 1.4beta releases, sys.version[:3] can be used.
4218+
4219+
On non-Unix systems, these variables are meaningless.
41544220

41554221
\item
4156-
While sites are strongly discouraged from modifying the standard
4157-
Python library (e.g. by adding site-specific modules or functions),
4158-
there is now a standard way to invoke site-specific features. The
4159-
standard module \code{site}, when imported, appends two site-specific
4160-
directories to the end of \code{sys.path}:
4161-
\code{\$prefix/lib/site-python} and
4162-
\code{\$exec_prefix/lib/site-python}, where \code{\$prefix} and
4163-
\code{\$exec_prefix} are the directories \code{sys.prefix} and
4222+
While sites are strongly discouraged from modifying the standard
4223+
Python library (like adding site-specific modules or functions), there
4224+
is now a standard way to invoke site-specific features. The standard
4225+
module \code{site}, when imported, appends two site-specific
4226+
directories to the end of \code{sys.path}:
4227+
\code{\$prefix/lib/site-python} and
4228+
\code{\$exec_prefix/lib/site-python}, where \code{\$prefix} and
4229+
\code{\$exec_prefix} are the directories \code{sys.prefix} and
41644230
\code{sys.exec_prefix} mentioned above.
41654231

4166-
\item
4167-
There's more. As I said, see \code{Misc/NEWS}...
4232+
After this path manipulation has been performed, an attempt is made to
4233+
import the module \code{sitecustomize}. Any \code{ImportError}
4234+
exception raised by this attempt is silently ignored.
41684235

41694236
\end{itemize}
41704237

4171-
4172-
4173-
41744238
\end{document}

0 commit comments

Comments
 (0)