Exception problems

Richard Jones rjones at ekit-inc.com
Wed Dec 4 22:12:53 EST 2002


On Thu, 5 Dec 2002 1:24 pm, Greg Ewing wrote:
> Richard Jones wrote:
> > The exception "name" also
> > differs - in a.py as-a-script, it's "__main__.FooExc" and in a.py
> > as-a-module and b.py it's "a.FooExc".
> >
> > Is this a bug or a feature?
>
> I'd call it a "well-known misfeature" (well-known to
> those that have been bitten by it before, anyway).
>
> When you invoke a .py file as a script, it gets
> turned into a module called __main__, regardless
> of the name of the file it came from.
>
> If the script then, directly or indirectly,
> imports itself by name, a *second*
> module is created and initialised from the
> same .py file.

This explains what I was observing, thanks for the explanation!


   Richard





More information about the Python-list mailing list