Show More
@@ -466,10 +466,35 b' python-profiler package from non-free.""")' | |||||
466 |
|
466 | |||
467 | @line_magic |
|
467 | @line_magic | |
468 | def tb(self, s): |
|
468 | def tb(self, s): | |
469 |
"""Print the last traceback |
|
469 | """Print the last traceback. | |
470 |
|
470 | |||
471 | See %xmode for changing exception reporting modes.""" |
|
471 | Optionally, specify an exception reporting mode, tuning the | |
472 | self.shell.showtraceback() |
|
472 | verbosity of the traceback. By default the currently-active exception | |
|
473 | mode is used. See %xmode for changing exception reporting modes. | |||
|
474 | ||||
|
475 | Valid modes: Plain, Context, Verbose, and Minimal. | |||
|
476 | """ | |||
|
477 | interactive_tb = self.shell.InteractiveTB | |||
|
478 | if s: | |||
|
479 | # Switch exception reporting mode for this one call. | |||
|
480 | # Ensure it is switched back. | |||
|
481 | def xmode_switch_err(name): | |||
|
482 | warn('Error changing %s exception modes.\n%s' % | |||
|
483 | (name,sys.exc_info()[1])) | |||
|
484 | ||||
|
485 | new_mode = s.strip().capitalize() | |||
|
486 | original_mode = interactive_tb.mode | |||
|
487 | try: | |||
|
488 | try: | |||
|
489 | interactive_tb.set_mode(mode=new_mode) | |||
|
490 | except Exception: | |||
|
491 | xmode_switch_err('user') | |||
|
492 | else: | |||
|
493 | self.shell.showtraceback() | |||
|
494 | finally: | |||
|
495 | interactive_tb.set_mode(mode=original_mode) | |||
|
496 | else: | |||
|
497 | self.shell.showtraceback() | |||
473 |
|
498 | |||
474 | @skip_doctest |
|
499 | @skip_doctest | |
475 | @line_magic |
|
500 | @line_magic |
General Comments 0
You need to be logged in to leave comments.
Login now