Hi,
I wrote the 'autoimp' module [1], which allows you to import lazy modules:
from autoimp import * (Import lazy wrapper objects around all modules; "lazy
modules" will turn into normal modules when an
attribute
is first accessed with getattr()).
from autoimp import A, B (Import specific lazy module wrapper objects).
The main point of autoimp is to make usage of the interactive Python prompt
more productive by including "from autoimp import *" in the PYTHONSTARTUP file.
Thus one can use:
>>> urllib2.urlopen('http://www.google.com').read()
>>> Image.open('test.bmp')
>>> pylab.plot([1,2],[3,4])
>>> scipy.linalg.eig([[1,2],[3,4]])
>>> ...
One can thenceforward use the interactive prompt without using the "import"
statement at all. In practice, I have found that there is little overhead in
time
and memory for the initial import of all lazy modules (assuming all of the
Python
module paths are on the local disk, and not on a network).
I have also found "autoimp" useful in writing normal Python applications; one
can
use "from autoimp import *" at the top of a Python source file and thus have all
Python modules available to that source file, which results in increased
efficiency of writing the program with the downside that one has to think more
carefully about global variables to avoid name conflict bugs.
Now because this feature is useful, I thought of writing a PEP to add the
"lazy import" functionality to the Python interpreter.
Specifically:
lazily import *
lazily import A, B, C
This would involve the introduction of a new keyword, such as "lazily".
The PEP should include extensions to the builtin Python __import__
(__lazilyimport__ ?)
and the imp and zipimport modules so that the new "lazy import" feature can be
fully utilized by "dynamic" Python code.
Closely related to the "autoimp" module is Philip Eby's Importing module [2].
The Importing
module has the ability to lazily import a single module as well as a number of
other features,
so Philip may wish to be involved, and features from Importing may be used in
the PEP if
desired.
Opinions?
[1]. http://cheeseshop.python.org/pypi/autoimp/1.0.2
[2]. http://peak.telecommunity.com/DevCenter/Importing
__
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
--
http://mail.python.org/mailman/listinfo/python-list