Simplifying imports?
Terry Hancock
hancock at anansispaceworks.com
Tue Sep 13 01:31:36 EDT 2005
On Monday 12 September 2005 10:09 pm, chapolim-colorado at bol.com.br wrote:
> I like to keep my classes each in a separate file with the same name of
> the class. The problem with that is that I end up with multiple imports
> in the beginning of each file, like this:
>
> from foo.Bar import Bar
> from foo.Blah import Blah
> from foo.Zzz import Zzz
>
> What I'd like to do would be to replace it all by a single line:
>
> from foo.* import *
>
> Of course, that doesn't work, but is there a way to do something like
> that?
Apparently "foo" is already a package defined using __init__.py,
so you know about that part already.
Just change its contents to read:
from Bar import Bar
from Blah import Blah
from Zzz import Zzz
Then whenever you need to use these classes, you only need:
from foo import Bar, Blah, Zzz
or
from foo import *
Cheers,
Terry
--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks http://www.anansispaceworks.com
More information about the Python-list
mailing list