Consider the following Python code segment:
from ipywidgets import Text, Button, Label, VBox, HBox, GridBox, Layout
def on_click(btn):
value.value += btn.description
def on_click_equals(btn):
value.value = eval(value.value)
The above code implements a simple calculator that evaluates a mathematical expression when a user clicks on the "=" button in a Jupyter notebook.
When I run this code on somebody else's Jupyter notebook (hosted on a server somewhere on the internet ), I get the following error message:
The 'value' trait of a Text instance must be a unicode string, but a value of 7 <class 'int'> was specified
However, when I run the same code in my local Visual Studio Code Jupyter notebook, I get no error message.
If I change the Python code above to look like:
from ipywidgets import Text, Button, Label, VBox, HBox, GridBox, Layout
def on_click(btn):
value.value += btn.description
def on_click_equals(btn):
value.value = str(eval(value.value)) #<--- adding str() fixed the problem
Then everything works correctly in both Visual Studio Code and on the other person's Jupyter server.
My question is: Why couldn't I see the error message in Visual Studio Code? How do I get Visual Studio Code to display Jupyter error messages like:
The 'value' trait of a Text instance must be a unicode string, but a value of 7 <class 'int'> was specified
just like error messages were displayed on the other person's Jupyter server on the internet?
question from:
https://stackoverflow.com/questions/66051313/how-do-you-get-visual-studio-code-to-show-jupyter-python-error-messages-when-run 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…