WG: [Tutor] Import multiple classes from one module

Andrei Kulakov ak@silmarill.org
Sat, 29 Sep 2001 12:06:42 -0400


On Sat, Sep 29, 2001 at 01:26:51PM +0200, Reto M. Kiefer wrote:
> > I have a module containing several classes, say,
> > c1, c2, c3.
> >
> > It seems that I have to import each class one by one like:
> >
> > from mymodule import c1
> > from mymodule import c2
> > from mymodule import c3
> >
> > What if there are 30 classes in that module that
> > I wanna import ? Should I make 30 imports or
> > there's a better way to do it ?
> 
> The way :
> 
> from mymodule import *
> 
> doesn't work?

If you use this method, you should know of it's dangers: it becomes rather
hard to tell where the module or function came from. Consider:

from mymod import *
from mymod2 import *

stuff()

Is stuff a builtin, did it come from mymod or mymod2 or is it defined
somewhere in the file? You can tell right after you wrote it, but will you
be able to tell 2 years later? What about someone else who has to maintain
or modify your code? Also, you can't reload modules if they're imported
like this.

In some cases it's acceptable but you have to be aware of these hiccups..

> 
> HTH and CU,
> 
> Reto
> 
> --
> Reto M. Kiefer | New Media Solutions
> Email:  reto@codedculture.com
> Web:    http://www.codedculture.com 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org