Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
python [2006/06/09 00:00]
a
python [2009/05/25 00:35] (current)
Line 2: Line 2:
  
 see: **[[http://www.red-sweater.com/blog/140/learn-python|Good article about learning python]]**, [[http://nodebox.net/]] see: **[[http://www.red-sweater.com/blog/140/learn-python|Good article about learning python]]**, [[http://nodebox.net/]]
 +
  
 ==== python interpreter (history + autocomplete) ==== ==== python interpreter (history + autocomplete) ====
  
 **''.pyrc''** **''.pyrc''**
-  try:  +   # startup script for python to enable saving of interpreter history and 
-          import readline +   # enabling name completion 
-  except ImportError: +    
-          print "Module readline not available." +   # import needed modules 
-  else+   import atexit 
-          import rlcompleter +   import os 
-          readline.parse_and_bind("tab: complete"+   import readline 
-  import os +   import rlcompleter 
-  histfile = os.path.join(os.environ["HOME"], ".pyhist") +    
-  try+   # where is history saved 
-          readline.read_history_file(histfile+   historyPath = os.path.expanduser("~/.pyhistory") 
-  except IOError: +    
-          pass +    # handler for saving history 
-  import atexit +    def save_history(historyPath=historyPath)
-  atexit.register(readline.write_history_file, histfile+       import readline 
- +       readline.write_history_file(historyPath
 +    
 +   # read history, if it exists 
 +   if os.path.exists(historyPath): 
 +       readline.read_history_file(historyPath
 +    
 +   # register saving handler 
 +   atexit.register(save_history) 
 +    
 +   # enable completion 
 +   readline.parse_and_bind('tab: complete'
 +    
 +   # cleanup 
 +   del os, atexit, readline, rlcompleter, save_history, historyPath 
 +   
 **''.bashrc''** **''.bashrc''**
   export PYTHONSTARTUP=~/.pyrc   export PYTHONSTARTUP=~/.pyrc
python.1149804020.txt.gz · Last modified: 2009/05/25 00:34 (external edit)
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0 ipv6 ready