[Python-Dev] Replacement for print in Python 3.0

Reinhold Birkenfeld reinhold-birkenfeld-nospam at wolke7.net
Thu Sep 1 18:57:34 CEST 2005

Guido van Rossum wrote:
> [Charles Cazabon]
>> >> Perhaps py3k could have a py2compat module.  Importing it could have the
>> >> effect of (for instance) putting compile, id, and intern into the global
>> >> namespace, making print an alias for writeln,
> [Greg Ewing]
>> > There's no way importing a module could add something that
>> > works like the old print statement, unless some serious
>> > magic is going on...
> [Reinhold Birkenfeld]
>> You'd have to enclose print arguments in parentheses. Of course, the "trailing
>> comma" form would be lost.
> And good riddance! The print statement harks back to ABC and even
> (unvisual) Basic. Out with it!

Here I have to agree with Barry. print is very handy, and print>> is, too.

I'd rather see exec and assert becoming a function.

> A transitional strategy could be to start designing the new API and
> introduce it in Python 2.x. Here's my strawman:
> (1) Add two new methods the the stream (file) API and extend write():
> stream.write(a1, a2, ...) -- equivalent to map(stream.write, map(str,
> [a1, a2, ...]))
> stream.writeln(a1, a2, ...) -- equivalent to stream.write(a1, a2, ..., "\n")
> stream.writef(fmt, a1, a2, ...) -- equivalent to stream.write(fmt %
> (a1, a2, ...))

Do we really need writef()? It seems to be not much better than its %-formatting

> (2) Add builtin functions write(), writeln(), writef() that call the
> corresponding method on sys.stdout. (Note: these should not just be
> the bound methods; assignment to sys.stdout should immediately affect
> those, just like for print. There's an important use case for this.)

If write* is introduced, this is absolutely necessary.


Mail address is perfectly valid!

More information about the Python-Dev mailing list