what's the general way of separating classes?

Felipe Almeida Lessa felipe.lessa at gmail.com
Mon Mar 20 17:28:51 CET 2006

Em Seg, 2006-03-20 às 16:01 +0000, John Salerno escreveu:
> Felipe Almeida Lessa wrote:
> > And create an program/modules/__init__.py that have something like
> > 
> > from program.modules.class1 import class1
> > from program.modules.class2 import class2
> I'm not sure I understand the point of those two lines, if you are going 
> to then do this:
> > And, in the rest of your program, you can import class1 and class2 by
> > just issuing
> > 
> > from program.modules import class1, class2
> How does the __init__ file help if you are still individually importing 
> class1 and class2 in each other module of your program?

Ermmm... Maybe I should give a bigger example? What's better, this

from program.modules.class1 import class1
from program.modules.class2 import class2
from program.modules.class3 import class3
from program.modules.class4 import class4
from program.modules.class5 import class5
from program.modules.class6 import class6
from program.modules.class7 import class7
from program.modules.class8 import class8
from program.modules.class9 import class9
from program.modules.class10 import class10
from program.modules.class11 import class11
from program.modules.class12 import class12
from program.modules.class13 import class13
from program.modules.class14 import class14
from program.modules.class15 import class15
from program.modules.class16 import class16
from program.modules.class17 import class17
from program.modules.class18 import class18
from program.modules.class19 import class19
from program.modules.class20 import class20

or this

from program.modules import (class1,  class2,  class3,  class4, 
                             class5,  class6,  class7,  class8,
                             class9,  class10, class11, class12,
                             class13, class14, class15, class16,
                             class17, class18, class19, class20,
                             class21, class22, class23, class24,
                             class25, class26, class27, class28,
                             class29, class30, class31, class32,
                             class33, class34, class35, class36,
                             class37, class38, class39, class40)


If you mean doing "from program.modules import *" of course you *can*,
but you *shouldn't*. It makes your code a mess after some time.


More information about the Python-list mailing list