Home > Python > Automatic Python imports with autoimp, lazy ones with Importing

Automatic Python imports with autoimp, lazy ones with Importing

June 12th, 2006

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.)

Python

  1. June 12th, 2006 at 12:57 | #1

    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.

  2. June 12th, 2006 at 19:23 | #2

    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')

  3. Jay
    June 12th, 2006 at 22:23 | #3

    Are there any drawbacks to doing this?

  4. June 21st, 2006 at 15:09 | #4

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

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

  1. June 12th, 2006 at 19:24 | #1