Is it possible to create my own trace in Python? I am trying to write a function raise_from()that mimics Python 3 raise ... from ....
raise_from()
raise ... from ...
def raise_from(exc, cause): """ Raises the Exception *exc* from the calling stack-frame, settings its ``__cause__`` to *cause*. """ exc.__cause__ = cause try: raise Exception except Exception: tb = sys.exc_info()[2] # Remove the last traceback entry. prelast_tb = tb while prelast_tb.tb_next: prelast_tb = prelast_tb.tb_next prelast_tb.tb_next = None raise type(exc), exc, tb
Unfortunately, instance attributes tracebackare read-only.
traceback
, , back-back, , list. , , , :, trace-back ( stdout,...)
tb_list = traceback.extract_tb(tb) tb_list = tb_list[:-1] #omitting the last trace-back entry tb_str = tb.format_list(tb_list) # print whatever
, TraceBack, @property .
Source: https://habr.com/ru/post/1543765/More articles:How to define observable loops - reactive-programmingEnviron ("USERNAME") in VBA returns "User" after updating Windows 8 - vbaWhat is the expected result of subscribing to a range? - swifthow to solve spring no bean named 'dataSource' defined? - springImport sqlite3.h into Swift project through Obj-C bridge header not working - sqliteIs there a Delphi RTL function that can convert the ISO 8601 base date format to TDate? - delphiprintf vs putchar - different output - cThe plot of geom_segment on the ggmap object in R-lines not appearing - rAVD Emulator does not display hardware buttons - androidThe best way to get visual elements in QML - qtAll Articles