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

I am sympathetic to the 'hiding bugs' argument in general, but what bugs would 
this proposal hide?  What bugs does print hide by auto-converting non-strings 
to strings?

I recently had the same thought as Raymond's: "it would be nice if str.join 
converted inputs to strings when needed."

I have always known that print() is slower in IDLE than in a console.  A recent 
SO question 
https://stackoverflow.com/questions/66286367/why-is-my-function-faster-than-pythons-print-function-in-idle
 showed that it could be 20X slower and asked why?  It turns out that while

print(*values, sep=sep, end=end, file=file) # is equivalent to 
file.write(sep.join(map(str, values))+end)

print must be implemented as the C equivalent of something like

first=True
for val in values:
    if first:
        first = False
    else
        file.write(sep)
    file.write(str(value))
file.write(end)

When sys.stdout is a screen buffer, the multiple writes effectively implement a 
join.  But in IDLE, each write(s) results in a separate socket.send(s.encode) 
and socket.receive).decode + text.insert(s, tag).  I discovered that removing 
nearly all the overhead from the very slow example with sep.join and end.join 
made the example only trivially slower on IDLE (5%) than the standard REPL.  In 
#43283 I added the option of speedups using .join and .format to the IDLE doc, 
but this workaround would be much more usable if map(str, x) were not needed.

----------
nosy: +terry.reedy

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

Reply via email to