question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

%%python prints traceback, no exception name or value

See original GitHub issue
%%python
def foo(x, y):
    return x / y

foo(1, 0)

in a metakernel_bash notebook shows a traceback, but doesn’t include the exception name and value:

  File "/Users/parente/miniconda3/envs/spylon-kernel-dev/lib/python3.6/site-packages/metakernel/magics/python_magic.py", line 25, in exec_code
    exec(code, globals())

  File "<string>", line 4, in <module>

  File "<string>", line 2, in foo

I know the exception name and description are available because running the function that does the exec for the python magic like so:

from metakernel.magics import python_magic
z = python_magic.exec_code('''
def foo(x, y):
    return x / y
foo(1, 0)
''', globals(), None)

print(z.ename) # 'ZeroDivisionError'
print(z.evalue) # ('division by zero',)

shows the ename and evalue attributes include the additional information that is missing from the magic’s default output of the traceback alone.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
parentecommented, Jun 13, 2017

Ha! I didn’t even notice the dupe output when I posted. Thanks for the fix (x2).

1reaction
dsblankcommented, May 21, 2017

I’m looking into this… appears to be a change upstream in jupyter api…

Read more comments on GitHub >

github_iconTop Results From Across the Web

traceback — Print or retrieve a stack traceback — Python 3.11 ...
Format the exception part of a traceback using an exception value such as given by sys.last_value . The return value is a list...
Read more >
How to catch and print the full exception traceback without ...
Assigning the traceback return value to a local variable in a function that is handling an exception will cause a circular reference.
Read more >
Understanding the Python Traceback
In the above traceback, the exception was a NameError , which means that there is a reference to some name (variable, function, class)...
Read more >
How to print exception stack trace in Python? - GeeksforGeeks
This method prints exception information and stack trace entries from traceback object tb to file. Parameters: This method accepts the ...
Read more >
traceback – Extract, format, and print exceptions and stack ...
A traceback is a stack trace from the point of an exception handler down the call chain to the point where the exception...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found