Python Forum
Print phenomenon - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Forum & Off Topic (https://python-forum.io/forum-23.html)
+--- Forum: Bar (https://python-forum.io/forum-27.html)
+--- Thread: Print phenomenon (/thread-38638.html)



Print phenomenon - DPaul - Nov-08-2022

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


RE: Print phenomenon - Gribouillis - Nov-08-2022

Please post complete runnable code that reproduces the bug.


RE: Print phenomenon - DeaD_EyE - Nov-08-2022

(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.


RE: Print phenomenon - DPaul - Nov-08-2022

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


RE: Print phenomenon - Larz60+ - Nov-08-2022

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.


RE: Print phenomenon - DPaul - Nov-09-2022

(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


RE: Print phenomenon - Larz60+ - Nov-09-2022

in your statement, it is an errror.
Print(e) must be written as print(e)

print is lower case! no capital letters at all.


RE: Print phenomenon - DPaul - Nov-09-2022

(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



RE: Print phenomenon - DeaD_EyE - Nov-09-2022

Because he did not define Print.