autoimp
Automatic Python imports.
Introduction
At the interactive Python prompt, I found myself wasting a significant
amount of time by repeatedly writing statements such as
import urllib2, os, socket. Every time that I opened a new Python
session, I needed to re-import all of the libraries that I intended to
work with.
The autoimp module imports all available Python modules
automatically:
>>> from autoimp import *
>>> os.stat('.')
>>> Image.open('test.bmp')
>>> pylab.plot([1,2],[3,4])
>>> scipy.linalg.eig([[1,2],[3,4]])
>>> ...
The modules imported from autoimp are proxy objects which
lazily load when they are first used. To properly use
autoimp, you should place the following code in your
PYTHONSTARTUP file:
from autoimp import *
Now, all modules are automatically imported and made available in your
interactive Python sessions. If your editor does not support
PYTHONPATH, see note [1].
Features
- Public domain, compatible with Python 2.1 - 2.5.
- Can be used in Python source code files.
- Tested with the Python standard library and extensions: CGKit, Numpy, Scipy, OpenGL, PIL, Pygame, and ODE.
- Works with documentation utilities such as pydoc and epydoc if
__all__ is defined.
- Does not currently work with py2exe and pyinstaller, because the installers cannot determine which modules were imported.
Current Version
Version 1.0.2 source code is available.
Version History
Version history (changelog):
Author
The autoimp source code and supporting documentation have
been placed in the public domain.
Please send patches and bug reports to my e-mail address:
>>> 'Y29ubmVsbHliYXJuZXNAZ21haWwuY29t'.decode('base64')
- Connelly Barnes
Footnotes
|
1.
| Alternatively, for editors such as IDLE
which do not load the PYTHONSTARTUP file after running a
script, you can (a) patch your editor or (b) use a hack to circumvent
the problem: add the following code to
Lib/site-packages/sitecustomize.py:
import autoimp; autoimp._export_builtins()
This hack will cause all available modules to be placed in the builtin
namespace of every Python script which is run; this can presumably
cause hard-to-find bugs. You have been warned.
|