Automatic Python imports with autoimp, lazy ones with Importing

Connelly Blog: Automatic Python imports with autoimp tries to make all modules/packages available without loading everything up. Interesting idea. Something that may also be interesting is using its recursive lazy loader in TG to not import the features you’re not using. The license is unknown, however. (Update: it’s public domain).
Update: odd to get two import-related packages in the same day. I’m uncertain about the automatic import thing, but Phillip Eby just released Importing which provides dynamic module loading (it also provides “load object Y from module X specified in python dotted notation string” utility functions, which could eliminate a utility we have in tg.util.)


5 Responses to “Automatic Python imports with autoimp, lazy ones with Importing”

Ian Bicking on June 12th, 2006 12:57 pm:

I think the motivation is good, but py.std (http://codespeak.net/py/current/doc/misc.html#the-py-std-hook or I wrote about it here: http://blog.ianbicking.org/py-std.html) serves a similar purpose, and is more explicit. The implementation is trivial. Putting it in __builtins__ is a little more controversial.


Connelly Barnes on June 12th, 2006 7:23 pm:

Neither autoimp nor Importing puts the imported modules in __builtins__. Instead, the imported, wrapped modules are typically placed in the caller’s globals().

The module autoimp was originally intended to automatically import all modules at the interactive prompt, and thus save the user from typing “py.std.*” or “import os, sys, urllib2, collections, bz2, zlib, …” The lazyModule class in Philip Eby’s Importing module loads a single module, instead of all modules. Thus the following are roughly equivalent:

>>> from autoimp import a, b, c

>>> a = lazyModule(‘a’)
>>> b = lazyModule(‘b’)
>>> c = lazyModule(‘c’)


import this. » Blog Archive » Dynamic module loading on June 12th, 2006 7:24 pm:

[...] Kevin Dangoor metions dynamic module loading: …Phillip Eby just released Importing which provides dynamic module loading (it also provides “load object Y from module X specified in python dotted notation stringâ€? utility functions, which could eliminate a utility we have in tg.util.) [...]


Jay on June 12th, 2006 10:23 pm:

Are there any drawbacks to doing this?


Tim Lesher on June 21st, 2006 3:09 pm:

Wow. My first blog post ever was a wish for just this:

http://apipes.blogspot.com/2004_08_01_apipes_archive.html