Commit 3c62d9e6 authored by Fred Drake's avatar Fred Drake

Several small changes, mostly to the markup, to improve consistency and

internal hyperlinking.  Move some things around, also for consistency
with other modules ("See also" stuff tends to live at the \section level,
before sub-sections, etc.).
parent 14ea85f3
\section{\module{atexit} --- \section{\module{atexit} ---
exit handlers} Exit handlers}
\declaremodule{standard}{atexit} \declaremodule{standard}{atexit}
\moduleauthor{Skip Montanaro}{skip@mojam.com} \moduleauthor{Skip Montanaro}{skip@mojam.com}
...@@ -14,7 +14,7 @@ executed upon normal interpreter termination. ...@@ -14,7 +14,7 @@ executed upon normal interpreter termination.
Note: the functions registered via this module are not called when the program is killed by a Note: the functions registered via this module are not called when the program is killed by a
signal, when a Python fatal internal error is detected, or when signal, when a Python fatal internal error is detected, or when
\code{os._exit()} is called. \function{os._exit()} is called.
This is an alternate interface to the functionality provided by the This is an alternate interface to the functionality provided by the
\code{sys.exitfunc} variable. \code{sys.exitfunc} variable.
...@@ -67,7 +67,8 @@ import atexit ...@@ -67,7 +67,8 @@ import atexit
atexit.register(savecounter) atexit.register(savecounter)
\end{verbatim} \end{verbatim}
\begin{seealso} \begin{seealso}
\seemodule{readline}{useful example of atexit to read and write readline \seemodule{readline}{Useful example of atexit to read and write
history files} \refmodule{readline} history files.}
\end{seealso} \end{seealso}
\section{\module{readline} --- \section{\module{readline} ---
Expose GNU readline functionality to Python} GNU readline interface}
\declaremodule{builtin}{readline} \declaremodule{builtin}{readline}
\platform{Unix}
\sectionauthor{Skip Montanaro}{skip@mojam.com} \sectionauthor{Skip Montanaro}{skip@mojam.com}
\modulesynopsis{GNU Readline in Python.} \modulesynopsis{GNU Readline in Python.}
\platform{UNIX}
The \module{readline} module defines a number of functions used either The \module{readline} module defines a number of functions used either
directly or from the \module{rlcompleter} module to facilitate completion directly or from the \refmodule{rlcompleter} module to facilitate
and history file read and write from the Python interpreter. completion and history file read and write from the Python
interpreter.
The \module{readline} module defines the following functions: The \module{readline} module defines the following functions:
\begin{funcdesc}{parse_and_bind}{string} \begin{funcdesc}{parse_and_bind}{string}
Parse and execute single line of a readline init file. Parse and execute single line of a readline init file.
\end{funcdesc} \end{funcdesc}
...@@ -33,19 +34,19 @@ The default filename is the last filename used. ...@@ -33,19 +34,19 @@ The default filename is the last filename used.
\begin{funcdesc}{read_history_file}{\optional{filename}} \begin{funcdesc}{read_history_file}{\optional{filename}}
Load a readline history file. Load a readline history file.
The default filename is ~/.history. The default filename is \file{\~{}/.history}.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{write_history_file}{\optional{filename}} \begin{funcdesc}{write_history_file}{\optional{filename}}
Save a readline history file. Save a readline history file.
The default filename is ~/.history. The default filename is \file{\~{}/.history}.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{set_completer}{\optional{function}} \begin{funcdesc}{set_completer}{\optional{function}}
Set or remove the completer function. Set or remove the completer function. The completer function is
The function is called as function(text, state), called as \code{\var{function}(\var{text}, \var{state})},
\code{for i in [0, 1, 2, ...]} until it returns a non-string. \code{for i in [0, 1, 2, ...]} until it returns a non-string.
It should return the next possible completion starting with 'text'. It should return the next possible completion starting with \var{text}.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{get_begidx}{} \begin{funcdesc}{get_begidx}{}
...@@ -64,27 +65,30 @@ Set the readline word delimiters for tab-completion. ...@@ -64,27 +65,30 @@ Set the readline word delimiters for tab-completion.
Get the readline word delimiters for tab-completion. Get the readline word delimiters for tab-completion.
\end{funcdesc} \end{funcdesc}
\subsection{Example}
\nodename{Readline Example}
The following example demonstrates how to use the \module{readline} module's \begin{seealso}
history reading and writing functions to automatically load and save a \seemodule{rlcompleter}{Completion of Python identifiers at the
history file named \code{.pyhist} from the user's home directory. The code interactive prompt.}
below would normally be executed automatically during interactive sessions \end{seealso}
from the user's PYTHONSTARTUP file.
\subsection{Example \label{readline-example}}
The following example demonstrates how to use the
\module{readline} module's history reading and writing functions to
automatically load and save a history file named \file{.pyhist} from
the user's home directory. The code below would normally be executed
automatically during interactive sessions from the user's
\envvar{PYTHONSTARTUP} file.
\begin{verbatim} \begin{verbatim}
>>> import os import os
>>> histfile = os.path.join(os.environ["HOME"], ".pyhist") histfile = os.path.join(os.environ["HOME"], ".pyhist")
>>> try: try:
>>> readline.read_history_file(histfile) readline.read_history_file(histfile)
>>> except IOError: except IOError:
>>> pass pass
>>> import atexit import atexit
>>> atexit.register(readline.write_history_file, histfile) atexit.register(readline.write_history_file, histfile)
>>> del os, histfile del os, histfile
\end{verbatim} \end{verbatim}
\begin{seealso}
\seemodule{rlcompleter}{completion of Python identifiers}
\end{seealso}
...@@ -2,12 +2,16 @@ ...@@ -2,12 +2,16 @@
Completion function for readline} Completion function for readline}
\declaremodule{standard}{rlcompleter} \declaremodule{standard}{rlcompleter}
\platform{Unix}
\sectionauthor{Moshe Zadka}{mzadka@geocities.com} \sectionauthor{Moshe Zadka}{mzadka@geocities.com}
\modulesynopsis{Python identifier completion in the readline library.} \modulesynopsis{Python identifier completion in the readline library.}
The \module{rlcompleter} module defines a completion function for The \module{rlcompleter} module defines a completion function for
the \module{readline} module by completing valid Python identifiers and the \refmodule{readline} module by completing valid Python identifiers
keyword. and keywords.
This module is \UNIX-specific due to it's dependence on the
\refmodule{readline} module.
The \module{rlcompleter} module defines the \class{Completer} class. The \module{rlcompleter} module defines the \class{Completer} class.
...@@ -47,7 +51,7 @@ Completer objects have the following method: ...@@ -47,7 +51,7 @@ Completer objects have the following method:
\begin{methoddesc}[Completer]{complete}{text, state} \begin{methoddesc}[Completer]{complete}{text, state}
Return the \var{state}th completion for \var{text}. Return the \var{state}th completion for \var{text}.
If called for \var{text} that doesn't includea period character If called for \var{text} that doesn't include a period character
(\character{.}), it will complete from names currently defined in (\character{.}), it will complete from names currently defined in
\refmodule[main]{__main__}, \refmodule[builtin]{__builtin__} and \refmodule[main]{__main__}, \refmodule[builtin]{__builtin__} and
keywords (as defined by the \refmodule{keyword} module). keywords (as defined by the \refmodule{keyword} module).
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment