Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Print phenomenon
#1
Hi,
I came across a "bug" that was hard to find.
Found it, but found no good explanation of the why.
try:
   do_stuff_1
   Print(result)
   do_stuff_2
except Exception as e:
   print(e)
This code did "do_stuff_1", but ignored the "Print(result)" and the do_stuff_2.
No error was printed.
Of course, you will have noticed that "Print(result)" is with a capital "P" , that was the problem.
Question:
Does "Print" have some special meaning in python, or why did I not get any error message.
(Windows 11, Python 3.10.1, Idle editor.)
thx,
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#2
Please post complete runnable code that reproduces the bug.
Reply
#3
(Nov-08-2022, 10:11 AM)DPaul Wrote: Does "Print" have some special meaning in python, or why did I not get any error message.

No, you created somewhere in your code the Print object, which seems to be callable.
Otherwise, you'll see the exception message: name 'Print' is not defined or 'XXX' is not callable.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#4
Ok, can't post the code, it was in the middle of a
ThreadPool, workers() function, you would need data.
I did not make a Print object, so I'll assume that it
had something to do with that ThreadPool.
(I can assure you the try-except did not say anything.)
thx,
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#5
As DeaD_EyE points out, there has to be an object named 'Print' with a capital 'P' in the code.
This is what you should look for.
python 'print' is all lower case.
Reply
#6
(Nov-08-2022, 11:39 PM)Larz60+ Wrote: As DeaD_EyE points out, there has to be an object named 'Print' with a capital 'P' in the code.
OK, I'll have to accept that, although no such thing exists in my code.
Considering the scope of things "Print(e)" inside a function, inside an "except Exception as e":
would be hard pressed not to show as an error. There is another possibility, come to think of it.

In another thread i was inquiring about monitoring the progress of a multithreading (workers)
process. Printing inside such a function is erratic anyway. Maybe i was impatient and the error
was somewhere in the pipeline, still to be printed when I stopped the program. (Because I saw something was wrong)
Without an error message,it took me some time to pinpoint the "Print".
I'm still open for suggestions on how to monitor multithreading progress without printing from within the ThreadPool (workers) function.
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#7
in your statement, it is an errror.
Print(e) must be written as print(e)

print is lower case! no capital letters at all.
Reply
#8
(Nov-09-2022, 02:21 PM)Larz60+ Wrote: Print(e) must be written as print(e)
@Larz: Yes, I know that.
My question was , why did it not print as an error, like it does here.
Paul

try:
   x = 2 + 2
   Print('x =',x)
   y = 2 + 2
except Exception as e:
   print(e)
Output:
name 'Print' is not defined
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#9
Because he did not define Print.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Forum Jump:

User Panel Messages

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