[issue43402] IDLE shell adds newline after print even when `end=''` is specificied

Terry J. Reedy report at bugs.python.org
Thu Mar 4 16:15:30 EST 2021


Terry J. Reedy <tjreedy at udel.edu> added the comment:

I don't know how many core devs would agree that inserting '\n' would be preferable.  They might say that users who want clean interaction should not use the 'end' parameter the way you did in interactive mode.

IDLE is more aimed at beginners and can be more protective and/or opinionated.  In any case, I agree with whoever wrote or edited this part of IDLE before me as to what IDLE should do.

There are also technical  issues.  Interactive python uses the common features of the various OS text and line-oriented terminal/consoles.  These do not know and do not care that they are displaying python input and output.  They display chars received from the executing program and have no way of knowing that the last n chars match python's sys.ps1 or sys.ps2.  The prompts comes from python executing "input(prompt)" after user code finishes.  To conditionally insert a newline, python would have to keep track of whether or not the last char sent by user code was a newline or not.

IDLE, on the other hand, is customized to run python code.  It *emulates* interactive mode with exec() calls.  IDLE, not python, displays prompts however programmed to do so.  It is trivial to check whether the last char inserted in the text widget is '\n' or not.

Side note: you only need '-i' for interactive mode when you also run a file because 'python -i' by itself is the same as 'python'.

'python -i somefile' is different from 'python somefile' because in the latter case, python exits after executing somefile, whereas in the former case, python executes 'input(sys.ps1)' and possibly 'input(sys.ps2)' until told to quit.  'Run module' in an IDLE editor emulates 'python -i <filename>'.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43402>
_______________________________________


More information about the Python-bugs-list mailing list