Error when using Custom Exception defined in a different python module.

pillappa at hotmail.com pillappa at hotmail.com
Sun May 6 15:28:46 EDT 2007


On May 6, 11:23 am, Rob Williscroft <r... at freenet.co.uk> wrote:
>  wrote innews:1178475284.092656.103710 at e65g2000hsc.googlegroups.comin
> comp.lang.python:
>
> > Hi,
>
> > I am hitting this error consistently and don't know why it's
> > happening. I would like to define all exceptions for my project in one
> > file and use them across the project. Here's a sample -
>
> > exceptions.py -
> > from exceptions import *
> >              raise MyException("Raise custom error")
>
> > When the above is run, I get the following error -
> > NameError: global name 'MyException' is not defined
>
> When you get this kind of error, goto a python prompt
> (type python at a command prompt, or click on IDLE)
> and try this:
>
> >>> import exceptions
> >>> help( exceptions )
>
> I got this response (clipped):
>
> Help on built-in module exceptions:
>
> NAME
>     exceptions - Python's standard exception class hierarchy.
>
> Another common module name to avoid is "test".
>
> Rob.
> --http://www.victim-prime.dsl.pipex.com/

Doh!

Thanks for correcting my error Rob.




More information about the Python-list mailing list