How to: Auto-import common modules in ipython shell

if you use ipython, save yourself some typing by importing common modules automatically on load.

edit your ipythonrc file (mine lives in ~/.ipython/) as such:
import_mod math os os.path sys random itertools re json hashlib time urllib urllib2 urlparse
import_some datetime datetime date timedelta
import_mod x y z is like: import x, y, z
import_some x y z is like: from x import y, z
drew@dimagi-drew:~$ ipython
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
IPython 0.10 — An enhanced Interactive Python.
In [1]: datetime.now()
Out[1]: datetime.datetime(2012, 4, 9, 12, 18, 44, 570264)
look ma, no imports!

Share

Tags

Similar Articles

The World's Most Powerful Mobile Data Collection Platform

Start a FREE 30-day CommCare trial today. No credit card required.

Get Started

Learn More

Get the latest news delivered
straight to your inbox