Automatic import ?

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Fri Mar 26 22:00:24 EDT 2010


On Fri, 26 Mar 2010 18:18:07 -0700, C. B. wrote:

> It takes time to write the relative importations, that's ok, but I think
> it could be more pleasant for the end-user to not have to write a huge
> list of "from mymodule import xxx" if it is possible to take advantage
> of automatic importations.

You mean by black magic? Something like this?


>>> GGG = "My really important value"
>>> from mymodule import AAA
>>> print AAA()
"something"
>>> print GGG
<class 'mymodule.GGG'>
>>> print "WTF happened to my important value???"
'magic ate it'


As a general rule, Python does not allow magic. One exception is:

from mymodule import *


however once you have been bitten by it, you will soon learn to avoid it 
as almost always a bad idea.



-- 
Steven



More information about the Python-list mailing list