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

pillappa at hotmail.com pillappa at hotmail.com
Sun May 6 14:14:44 EDT 2007


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 -

class MyException(StandardError):
    def __init__(self, error):
        self.myerror = error

tests.py -

from exceptions import *

class Test:
    def __init__(self,filename):
        if filename == "":
             raise MyException("Raise custom error")

if __name__ == "__main__" :
   test = Test("")


When the above is run, I get the following error -
NameError: global name 'MyException' is not defined

Thanks
loganwol




More information about the Python-list mailing list