-
Book Overview & Buying
-
Table Of Contents
Python Illustrated
By :
Errors can always happen. For example, you may try to run this Python program:
print(age)
You’d get an output like this:
ERROR!
Traceback (most recent call last):
File "<main.py>", line 1, in <module>
NameError: name 'age' is not defined
We get a NameError here (which would be really funny if the variable were called name). This is because we are trying to access a variable called age, which we don’t have. Since it doesn’t have that variable, Python can’t print it. It would be like giving Wiesje a command we never taught her. What would a dog do if we told it to lemon?

The output shows the traceback, sometimes also called stacktrace. In this case, it’s only one line. It could be multiple lines, and if so, then it shows the path through the code that happened before the error occurred. This helps in figuring out what went wrong. In this case, it’s simple...