Sep-27-2023, 08:14 PM
(This post was last modified: Sep-27-2023, 08:25 PM by deanhystad.)
This is the python expression that raises the exception.
The expression on line 10 raises an exception with this message:
Another example might help. I run this code:
raise NameError(f"Use of {name} not allowed")It is line 10 in your posted code.
The expression on line 10 raises an exception with this message:
Error:NameError: Use of pow not allowed
The f"string replaces {name} with "pow", the str referenced by name. This changes the str passed to the exception. It does not rewrite the code on line 10.Another example might help. I run this code:
x = list("ABC") for i in range(4): print(x[i])I get an index error.
Error:A
B
C
Traceback (most recent call last):
File "...", line 3, in <module>
print(x[i])
IndexError: list index out of range
The line before the "IndexError" message is the statement that raised the exception. It says "print(x[i])". It does not say "print(x[3])". Granted, it would be very cool if error reporting replaced variables with their current values at the time of the error, but that is not what Python does. It might not even be possible. Accessing the variable value may be the reason for the exception.