[Python-Dev] Replacement for print in Python 3.0

John Hazen john at hazen.net
Fri Sep 2 23:18:14 CEST 2005

I like the elegance of python, and read py-dev for my own edification.
Since I believe I still have somewhat of a "beginner's mind" regarding
python, I'll chime in with my opinions.

First of all, I dislike 'writeln', for two reasons:
1) The name.  I always want to mentally pronounce it 'ritt-linn'.  If we
*must* have this function, I'd prefer 'writeline'.

2) 'writeln' is a convenience function.  A convenience function should
be convenient!  It seems to me that the most common (and convenient) use
case is adding spaces between the arguments /and/ adding the newline.
Since this is the same as the current default behavior of 'print', I
suggest we use that name.

So, after reading all the messages, it turns out my proposal is the same
as STeVe's:  all streams grow a 'print' method, and the builtin print
function just be an alias to sys.stdout.print.

Originally, I thought I preferred the statement version of print, but as
long as the basic behavior of print is kept, I could get used to adding
parens in my typing.  The consistency calling the print builtin function
with the stream.print method is nicer than the keystroke savings of no
parens required by the statement.  Having print as a function removes
the need for ">>" too ('stream.print(foo)' instead of 'print >>stream

I'm OK with losing the trailing-comma behavior, as I think 'write'
should be used for anything beyond the basic default usecase.

To summarize:

+1  STeVe's proposal (stream.print for all streams, print builtin which
    maps to sys.stdout.print)

+0  status quo

-1  Guido's proposal (stream.write and stream.writeln for all streams,
    write and writeln builtins which map to sys.stdout)


For reference:

* Steven Bethard <steven.bethard at gmail.com> [2005-09-02 13:06]:
> Basically, my proposal suggests that files (and
> other streams) gain a print method like:
>     class file(object):
>         ...
>         def print(self, *args):
>             self.write(' '.join(str(arg) for arg in args))
>             self.write('\n')
> and the print statement becomes the builtin print() function, defined like:
>     def print(*args):
>         sys.stdout.print(*args)

More information about the Python-Dev mailing list