Python Forum
problem in output of a function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problem in output of a function
#4
This is the python expression that raises the exception.
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.
akbarza likes this post
Reply


Messages In This Thread
problem in output of a function - by akbarza - Sep-27-2023, 06:34 AM
RE: problem in output of a function - by deanhystad - Sep-27-2023, 12:47 PM
RE: problem in output of a function - by akbarza - Sep-27-2023, 08:02 PM
RE: problem in output of a function - by deanhystad - Sep-27-2023, 08:14 PM
RE: problem in output of a function - by akbarza - Sep-27-2023, 08:20 PM
RE: problem in output of a function - by deanhystad - Sep-27-2023, 08:30 PM
RE: problem in output of a function - by akbarza - Sep-28-2023, 06:59 AM
RE: problem in output of a function - by snippsat - Sep-28-2023, 03:26 PM
RE: problem in output of a function - by akbarza - Sep-29-2023, 07:31 AM
RE: problem in output of a function - by snippsat - Sep-29-2023, 11:13 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in output of a snippet code akbarza 2 1,233 Feb-28-2024, 07:15 PM
Last Post: deanhystad
  output shape problem with np.arange alan6690 5 2,280 Dec-26-2023, 05:44 PM
Last Post: deanhystad
  Python Pandas Syntax problem? Wrong Output, any ideas? Gbuoy 2 1,812 Jan-18-2023, 10:02 PM
Last Post: snippsat
  Facing problem with Pycharm - Not getting the expected output amortal03 1 1,365 Sep-09-2022, 05:44 PM
Last Post: Yoriz
  How to print the output of a defined function bshoushtarian 4 2,244 Sep-08-2022, 01:44 PM
Last Post: deanhystad
  output correction using print() function afefDXCTN 3 13,381 Sep-18-2021, 06:57 PM
Last Post: Sky_Mx
  python prints none in function output chairmanme0wme0w 3 2,981 Jul-07-2021, 05:18 PM
Last Post: deanhystad
  print function output wrong with strings. mposwal 5 4,218 Feb-12-2021, 09:04 AM
Last Post: DPaul
  Output with none, print(x) in function Vidar567 3 3,701 Nov-24-2020, 05:40 PM
Last Post: deanhystad
  single input infinite output problem Chase91 2 2,664 Sep-23-2020, 10:01 PM
Last Post: Chase91

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020