![]() |
Pythonn 3 getting the __traceback__attribute of an exception - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Pythonn 3 getting the __traceback__attribute of an exception (/thread-22405.html) |
Pythonn 3 getting the __traceback__attribute of an exception - piscvau - Nov-11-2019 Python3 documentation states: A traceback object is normally created automatically when an exception is raised and attached to it as the __traceback__ attribute, which is writable. What is the trick to get this traceback or what is wrong into my code. import traceback class MyException(Exception): def __init__(self, mymessage): super().__init__ # do special things (print, mymessage) def essai(): raise MyException(' myp message') if __name__ == '__main__': essai() RE: Pythonn 3 getting the __traceback__attribute of an exception - Gribouillis - Nov-11-2019 Use if __name__ == '__main__': try: essai() except Exception as exc: t = exc.__traceback__ print(t) |