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

Skip to content

Commit 7238988

Browse files
committed
Fixed example to load the startup file from a script (didn't test for the
file's existance). Removed some XXX comments about extension modules which support pickling. Added text from AMK about the readline and rlcompleter modules. Thanks, AMK!
1 parent 003d8da commit 7238988

2 files changed

Lines changed: 60 additions & 12 deletions

File tree

Doc/tut.tex

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,15 +317,18 @@ \subsection{The Interactive Startup File}
317317
this file.
318318

319319
If you want to read an additional start-up file from the current
320-
directory, you can program this in the global start-up file, e.g.
321-
\samp{execfile('.pythonrc')}. If you want to use the startup file
322-
in a script, you must write this explicitly in the script:
320+
directory, you can program this in the global start-up file,
321+
e.g.\ \samp{execfile('.pythonrc')}\indexii{.pythonrc.py}{file}. If
322+
you want to use the startup file in a script, you must do this
323+
explicitly in the script:
323324

324325
\begin{verbatim}
325326
import os
326-
execfile(os.environ['PYTHONSTARTUP'])
327+
if os.path.isfile(os.environ['PYTHONSTARTUP']):
328+
execfile(os.environ['PYTHONSTARTUP'])
327329
\end{verbatim}
328330

331+
329332
\chapter{An Informal Introduction to Python}
330333
\label{informal}
331334

@@ -2313,8 +2316,7 @@ \subsection{The \module{pickle} Module}
23132316
same program; the technical term for this is a \dfn{persistent}
23142317
object. Because \module{pickle} is so widely used, many authors who
23152318
write Python extensions take care to ensure that new data types such
2316-
as matrices, XXX more examples needed XXX, can be properly pickled and
2317-
unpickled.
2319+
as matrices can be properly pickled and unpickled.
23182320
23192321
23202322
@@ -3454,6 +3456,28 @@ \section{Key Bindings}
34543456
in your \file{\$HOME/.inputrc}. (Of course, this makes it hard to type
34553457
indented continuation lines...)
34563458
3459+
Automatic completion of variable and module names is optionally
3460+
available. To enable it in the interpreter's interactive mode, add
3461+
the following to your \file{\$HOME/.pythonrc} file:% $ <- bow to font-lock
3462+
\indexii{.pythonrc.py}{file}%
3463+
\refstmodindex{rlcompleter}%
3464+
\refbimodindex{readline}
3465+
3466+
\begin{verbatim}
3467+
import rlcompleter, readline
3468+
readline.parse_and_bind('tab: complete')
3469+
\end{verbatim}
3470+
3471+
This binds the TAB key to the completion function, so hitting the TAB
3472+
key twice suggests completions; it looks at Python statement names,
3473+
the current local variables, and the available module names. For
3474+
dotted expressions such as \code{string.a}, it will evaluate the the
3475+
expression up to the final \character{.} and then suggest completions
3476+
from the attributes of the resulting object. Note that this may
3477+
execute application-defined code if an object with a
3478+
\method{__getattr__()} method is part of the expression.
3479+
3480+
34573481
\section{Commentary}
34583482
\label{commentary}
34593483

Doc/tut/tut.tex

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,15 +317,18 @@ \subsection{The Interactive Startup File}
317317
this file.
318318

319319
If you want to read an additional start-up file from the current
320-
directory, you can program this in the global start-up file, e.g.
321-
\samp{execfile('.pythonrc')}. If you want to use the startup file
322-
in a script, you must write this explicitly in the script:
320+
directory, you can program this in the global start-up file,
321+
e.g.\ \samp{execfile('.pythonrc')}\indexii{.pythonrc.py}{file}. If
322+
you want to use the startup file in a script, you must do this
323+
explicitly in the script:
323324

324325
\begin{verbatim}
325326
import os
326-
execfile(os.environ['PYTHONSTARTUP'])
327+
if os.path.isfile(os.environ['PYTHONSTARTUP']):
328+
execfile(os.environ['PYTHONSTARTUP'])
327329
\end{verbatim}
328330

331+
329332
\chapter{An Informal Introduction to Python}
330333
\label{informal}
331334

@@ -2313,8 +2316,7 @@ \subsection{The \module{pickle} Module}
23132316
same program; the technical term for this is a \dfn{persistent}
23142317
object. Because \module{pickle} is so widely used, many authors who
23152318
write Python extensions take care to ensure that new data types such
2316-
as matrices, XXX more examples needed XXX, can be properly pickled and
2317-
unpickled.
2319+
as matrices can be properly pickled and unpickled.
23182320
23192321
23202322
@@ -3454,6 +3456,28 @@ \section{Key Bindings}
34543456
in your \file{\$HOME/.inputrc}. (Of course, this makes it hard to type
34553457
indented continuation lines...)
34563458
3459+
Automatic completion of variable and module names is optionally
3460+
available. To enable it in the interpreter's interactive mode, add
3461+
the following to your \file{\$HOME/.pythonrc} file:% $ <- bow to font-lock
3462+
\indexii{.pythonrc.py}{file}%
3463+
\refstmodindex{rlcompleter}%
3464+
\refbimodindex{readline}
3465+
3466+
\begin{verbatim}
3467+
import rlcompleter, readline
3468+
readline.parse_and_bind('tab: complete')
3469+
\end{verbatim}
3470+
3471+
This binds the TAB key to the completion function, so hitting the TAB
3472+
key twice suggests completions; it looks at Python statement names,
3473+
the current local variables, and the available module names. For
3474+
dotted expressions such as \code{string.a}, it will evaluate the the
3475+
expression up to the final \character{.} and then suggest completions
3476+
from the attributes of the resulting object. Note that this may
3477+
execute application-defined code if an object with a
3478+
\method{__getattr__()} method is part of the expression.
3479+
3480+
34573481
\section{Commentary}
34583482
\label{commentary}
34593483

0 commit comments

Comments
 (0)