Archive

Posts Tagged ‘python shell’

Add History and Tab Completion to the Default Python Shell

Problem
You want history and TAB completion in your default Python shell. You are aware of bpython and ipython, but you miss this functionality in the default shell.

Solution
Edit ~/.bashrc:

# ~/.bashrc
export PYTHONSTARTUP=$HOME/.pythonstartup.py

Download pythonstartup.py from here and rename it to ~/.pythonstartup.py.

the bpython interpreter

August 14, 2011 Leave a comment

“bpython is a fancy interface to the Python interpreter for Unix-like operating systems (I hear it works fine on OS X). It is released under the MIT License. It has the following features:

  • In-line syntax highlighting.
  • Readline-like autocomplete with suggestions displayed as you type.
  • Expected parameter list for any Python function.
  • “Rewind” function to pop the last line of code from memory and re-evaluate.
  • Send the code you’ve entered off to a pastebin.
  • Save the code you’ve entered to a file.
  • Auto-indentation.
  • Python 3 support.

For more, see our about-page or just skip right to the screenshots.”

Installation

sudo apt-get install bpython

Tip: add the following line to your ~/.bashrc file:

alias bpy='bpython'

Then you can start the bpython interpreter with “p“. Short and simple :)

Alternatives

  • classic “python” interpreter
  • ipython

IPython, an enhanced Python shell

March 19, 2011 Leave a comment

IPython is an interactive shell for the Python programming language that offers enhanced introspection, additional shell syntax, syntax highlighting, tab completion and rich history. It is a component of the SciPy package.” (source)

Links:

In the book Python for Unix and Linux System Administration, there is a long chapter (Ch. 2) dedicated to IPython!

Installation and usage
Install it via apt-get:

sudo apt-get install ipython

I made the alias “ip” for the command “ipython”. Note that there is a command “ip” for manipulating routing and tunnels that the alias will hide, but it’s not likely I’ll ever use that command.

alias ip='ipython'

The config file of IPython is located at ~/.ipython/ipy_user_conf.py.

Categories: python Tags: , ,