[Python-checkins] CVS: python/dist/src/Doc/tut tut.tex,1.133.2.4,1.133.2.5

Fred L. Drake fdrake@users.sourceforge.net
Wed, 18 Jul 2001 12:21:45 -0700


Update of /cvsroot/python/python/dist/src/Doc/tut
In directory usw-pr-cvs1:/tmp/cvs-serv16039/tut

Modified Files:
      Tag: release21-maint
	tut.tex 
Log Message:

Add a more substantial example startup file for the interactive shell;
sample startup script provided by Itamar Shtull-Trauring.

This closes SF patch #410890.

Add some logical markup where it was missing.


Index: tut.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/tut/tut.tex,v
retrieving revision 1.133.2.4
retrieving revision 1.133.2.5
diff -C2 -r1.133.2.4 -r1.133.2.5
*** tut.tex	2001/06/29 17:51:42	1.133.2.4
--- tut.tex	2001/07/18 19:21:43	1.133.2.5
***************
*** 4060,4071 ****
  \end{verbatim}
  
! This binds the TAB key to the completion function, so hitting the TAB
! key twice suggests completions; it looks at Python statement names,
! the current local variables, and the available module names.  For
! dotted expressions such as \code{string.a}, it will evaluate the the
! expression up to the final \character{.} and then suggest completions
! from the attributes of the resulting object.  Note that this may
! execute application-defined code if an object with a
  \method{__getattr__()} method is part of the expression.
  
  
--- 4060,4108 ----
  \end{verbatim}
  
! This binds the \kbd{Tab} key to the completion function, so hitting
! the \kbd{Tab} key twice suggests completions; it looks at Python
! statement names, the current local variables, and the available module
! names.  For dotted expressions such as \code{string.a}, it will
! evaluate the the expression up to the final \character{.} and then
! suggest completions from the attributes of the resulting object.  Note
! that this may execute application-defined code if an object with a
  \method{__getattr__()} method is part of the expression.
+ 
+ A more capable startup file might look like this example.  Note that
+ this deletes the names it creates once they are no longer needed; this
+ is done since the startup file is executed in the same namespace as
+ the interactive commands, and removing the names avoids creating side
+ effects in the interactive environments.  You may find it convenient
+ to keep some of the imported modules, such as \module{os}, which turn
+ out to be needed in most sessions with the interpreter.
+ 
+ \begin{verbatim}
+ # Add auto-completion and a stored history file of commands to your Python
+ # interactive interpreter. Requires Python 2.0+, readline. Autocomplete is
+ # bound to the Esc key by default (you can change it - see readline docs).
+ #
+ # Store the file in ~/.pystartup, and set an environment variable to point
+ # to it, e.g. "export PYTHONSTARTUP=/max/home/itamar/.pystartup" in bash.
+ #
+ # Note that PYTHONSTARTUP does *not* expand "~", so you have to put in the
+ # full path to your home directory.
+ 
+ import atexit
+ import os
+ import readline
+ import rlcompleter
+ 
+ historyPath = os.path.expanduser("~/.pyhistory")
+ 
+ def save_history(historyPath=historyPath):
+     import readline
+     readline.write_history_file(historyPath)
+ 
+ if os.path.exists(historyPath):
+     readline.read_history_file(historyPath)
+ 
+ atexit.register(save_history)
+ del os, atexit, readline, rlcompleter, save_history, historyPath
+ \end{verbatim}