Import order question

Chris Angelico rosuav at
Tue Feb 18 22:02:26 CET 2014

On Wed, Feb 19, 2014 at 7:41 AM, Rick Johnson
<rantingrickjohnson at> wrote:
>     #
>     from ui_mod1 import *
>     from ui_mod2 import *
>     from ui_mod3 import *
>     from ui_mod4 import *
> At least by this method i can maintain the code base without
> wearing-out my scroll finger and eventually loosing my mind.
> THE MORAL: With very few exceptions, please put EVERY class
> in it's own module.

Absolutely definitely not. If you're going to import * into every
module, just write it all in a single source file. Otherwise, when
someone tries to find the source code for some particular class or
function, s/he has to go digging through all five source files - first
the utterly useless merge-point, then the four others, because there's
no way to know which one has it.

Python could make this easier for us, by retaining the origin of every
function and class. And maybe it's already there, but I don't know
about it. But even if it did exist (by the way, it would be useful for
other things than just taming a mad layout like this), it'd still be
better to keep everything combined, because the origin of a
function/class could just as easily go to the exact line as to the

A module is a namespace. It should be used as such. If you want a
package, use a package. There's no point putting each class out
separate unless you really need that.


More information about the Python-list mailing list