Terry J. Reedy <tjre...@udel.edu> added the comment:

If you run in windowed mode, you are expected to either not use sys.stdout or 
to provide a working sys.stdout object.  I am not sure if that is explicitly 
documented as I cannot find python.exe and pythonw.exe or .py or .pyw in the 
index and
https://docs.python.org/3/using/windows.html#python-launcher-for-windows
does not mention the pyw version.

But this is not really a windowed mode issue.  In a Windows console:
>>> print('hello')
hello
>>> import sys; sys.stdout = None
>>> print('hello')
>>> sys.stdout = sys.__stdout__
>>> print('hello')
hello

print and pprint act differently because pprint uses stream.write without 
try/except.  Check the doc or code.  So pprint users must run it with a stream 
with that method.  Otherwise, failure is to be expected.

If you try to print to None, print defaults to sys.stdout.  The doc does not 
define what happens when the latter is None.  On CPython, print passes.  But 
maybe this is left undefined intentionally.  It must either check that file is 
not None or catch the AttributeError.

>Shouldn't it say that it can't print because there's no stdout? 
How could it if there is no channel to speak?  I guess Guido decided to 
silently pass rather than silently exit.  Debug prints should not crash a 
program.

So closing as 'Not a bug' would be one appropriate resolution for this issue.

----------
nosy: +terry.reedy
type: behavior -> 

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue41546>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to