Válas Péter wrote:
Hi,

my code is (Python 2.5):

class SomeError(Error):
  """Uff!"""
raise SomeError, "blahblah"

Screen result:
__main__.SomeError: "blahblah"


I get

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'Error' is not defined



How can I make "__main__" disappear from output?
Thanks

You should inherit exceptions from the Exception class:


class SomeError(Exception):
    pass


If you put this in a module, then your exception will print:


<name of the module>.SomeError: "blahblah"


which is exactly what you need when debugging. Only built-in exceptions don't print the module name.

If you don't put it in a module, but just enter it at the interactive interpreter, it goes into a special module called "__main__". You just have to live with it.



--
Steven

_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to