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

Tim Peters tim_one@users.sourceforge.net
Fri, 20 Jul 2001 23:07:14 -0700


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

Modified Files:
      Tag: descr-branch
	tut.tex 
Log Message:
Merge of trunk delta date2001-07-17b to date2001-07-21.  See PLAN.txt.


Index: tut.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/tut/tut.tex,v
retrieving revision 1.144
retrieving revision 1.144.2.1
diff -C2 -r1.144 -r1.144.2.1
*** tut.tex	2001/07/14 02:14:42	1.144
--- tut.tex	2001/07/21 06:07:12	1.144.2.1
***************
*** 4069,4080 ****
  \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.
  
  
--- 4069,4117 ----
  \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}