How to remove "__main__." from the beginning of user-created exception classes in Python

Viewed 3689

Is there a way to get a "prettier" exception rather than one prefaced with __main__MyExceptionTitle?

Example:

>>> class BadThings(Exception):
...     def __init__(self, msg):
...         self.msg = msg
...         return
... 
>>> class BadThings(Exception):
...     def __init__(self, msg):
...         self.msg = msg
...         return
...     def __str__(self):
...         return self.msg
... 
>>> raise BadThings("This is really, really bad")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
__main__.BadThings: This is really, really bad

I would like it to just say:

BadThings: This is really, really bad

Just as if one types:

>>> raise Exception("This, too, is really, really bad")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
Exception: This, too, is really, really bad

I would like the __main__. gone!

Thanks, Narnie

4 Answers
Related