views:

967

answers:

3

When starting a django application using python manage.py shell, I get an InteractiveConsole shell - I can use tab completion, etc.

Python 2.5.1 (r251:54863, Apr 15 2008, 22:57:26) 
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)

When just starting a python interpreter using python, it doesn't offer tab completion.

Can someone tell me what django is doing to give me an interactive console, or what I need to do to start an interactive console without a django app?

+10  A: 

I think django does something like http://www.python.org/doc/2.5.2/lib/module-rlcompleter.html

If you want to have a really good interactive interpreter have a look at http://ipython.scipy.org/.

Peter Hoffmann
I second the recommendation of IPython.
Lawrence Johnston
+8  A: 

I may have found a way to do it.

Create a file .pythonrc

# ~/.pythonrc
# enable syntax completion
try:
    import readline
except ImportError:
    print "Module readline not available."
else:
    import rlcompleter
    readline.parse_and_bind("tab: complete")

then in your .bashrc file, add

export PYTHONSTARTUP=~/.pythonrc

That seems to work.

ashchristopher
+2  A: 

For the record, this is covered in the tutorial: http://docs.python.org/tutorial/interactive.html

Thomas Wouters