Welcome, guest | Sign In | My Account | Store | Cart
#!/usr/bin/env python

"""
Python interpreter auto-completion, history and colored tracebacks.
Installation:

 $ wget http://code.activestate.com/recipes/578098/download/1/ -O ~/.pythonstart
 $ echo "
export PYTHONSTARTUP=~/.pythonstart" >> ~/.bashrc
 $ source ~/.bashrc
"""


# Author: Giampaolo Rodola' <g.rodola [AT] gmail [DOT] com>
# License: MIT

if not hasattr(__name__, "__file__"):  # interpreter mode

   
def autocomplete():
       
import atexit
       
import os
       
import readline
       
import rlcompleter

       
def save_history():
            readline
.set_history_length(10000)
            readline
.write_history_file(history_path)

        history_path
= os.path.expanduser("~/.pyhistory")
       
if os.path.exists(history_path):
            readline
.read_history_file(history_path)
        atexit
.register(save_history)
        readline
.parse_and_bind('tab: complete')

    autocomplete
()

   
del autocomplete

Diff to Previous Revision

--- revision 4 2013-10-04 22:22:43
+++ revision 5 2014-01-09 10:04:47
@@ -1,7 +1,7 @@
 
#!/usr/bin/env python
 
 
"""
-Python interpreter auto-completion and history.
+Python interpreter auto-completion, history and colored tracebacks.
 Installation:
 
  $ wget http://code.activestate.com/recipes/578098/download/1/ -O ~/.pythonstart
@@ -19,14 +19,17 @@
         import os
         import readline
         import rlcompleter
+
+        def save_history():
+            readline.set_history_length(10000)
+            readline.write_history_file(history_path)
+
         history_path = os.path.expanduser("
~/.pyhistory")
-        def save_history():
-           readline.set_history_length(10000)
-           readline.write_history_file(history_path)
         if os.path.exists(history_path):
-           readline.read_history_file(history_path)
+            readline.read_history_file(history_path)
         atexit.register(save_history)
         readline.parse_and_bind('tab: complete')
 
     autocomplete()
+
     del autocomplete

History