Exceptions and modules

Peter Hansen peter at engcorp.com
Fri Jul 4 13:57:24 EDT 2003


Duncan Booth wrote:
> 
> westernsam at hotmail.com (sam) wrote in
> news:292c8da4.0307040627.59acda19 at posting.google.com:
> 
> > So the Exception isn't recognised even though it has the same
> > namespace and name as the exception defined in the module. I have to
> > uncomment the 7th line to get my example to behave as I would like it
> > to.
> >
> > Is this a bug/feature? Is there any reason why it shouldn't work the
> > way I expect it to?
> 
> It's a feature, and it probably ought to be in the FAQ in some form.
[snip explanation]

And the solution is to avoid putting things into your __main__ module
(the one run from the command line) which other modules need to find
by importing it.  If the application is so complex that it needs to 
have multiple modules, make the main one do something simple like 
import an Application class from somewhere else, instantiate it, and
call .run() on it (or whatever...).

-Peter




More information about the Python-list mailing list