Again: Please hear my plea: print without softspace
David MacQuigg
dmq at gain.com
Thu Mar 4 12:14:18 EST 2004
On Thu, 04 Mar 2004 12:52:27 GMT, Dang Griffith
>On Tue, 02 Mar 2004 10:32:35 -0700, David MacQuigg wrote:
>
>>The 'print' statement is just shortcut for 'sys.stdout.write' with
>>some convenience features suitable for most users. If you need
>>something else, just define your own shortcut, don't deprecate a
>>statement that is exactly what most users want.
>
>'print' is not a shortcut for 'sys.stdout.write'.
>'print' is a statement. 'sys.stdout.write' is a function.
>You can't define a shortcut for a statement.
I'm not using the word 'shortcut' very precisely. Mark Lutz says what
I mean more clearly in Learning Python, 2nd ed. p. 143: "the print
statement ... provides a user-friendly interface to the sys.stdout
object, with bit of default formatting." I conclude from this that
'print' has no special functionality unavailable through the stdout
object, and that the proper way to change the default user-friendly
interface is to write a new one, doing just what 'print' does, but
with different defaults.
What I think is going on "under the hood" with the print statement is:
def print(*args):
for arg in args:
sys.stdout.write(arg)
sys.stdout.write(' ')
sys.stdout.write('\n')
To make a variation on this, just add or delete the extra formatting.
Of course, we need to call it something besides the keyword 'print'.
-- Dave
More information about the Python-list
mailing list