Importing modules

Aahz aahz at pythoncraft.com
Fri Jan 30 13:56:20 EST 2009


In article <631e2879-6171-417e-8254-7f78c8cfc685 at i24g2000prf.googlegroups.com>,
alex23  <wuwei23 at gmail.com> wrote:
>
>If you're having to set up your imports in a specific order, odds are
>you have either a circular dependency or are overusing 'from <module>
>import *'. You should -never- (IMO) do something like 'from <some
>library> import x, y, z' in module 'a' and then 'from a import *' in
>module 'b'. If 'b' uses x, y & z, it should import them itself. If you
>-must- use 'import *', specify exactly what should be exported via
>'__all__'...in most cases, it should be restricted to only objects
>defined within that module.

There's one other way to run into this problem: I forget the exact
mechanics, but if you mix up absolute and relative imports for modules
inside packages, you can get namespace problems.  (It's also possible
newer versions of Python don't have this issue.)
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

Weinberg's Second Law: If builders built buildings the way programmers wrote 
programs, then the first woodpecker that came along would destroy civilization.



More information about the Python-list mailing list