[Python-Dev] Replacement for print in Python 3.0

Guido van Rossum guido at python.org
Thu Sep 1 16:58:08 CEST 2005

[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!

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, ...))

(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.)

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list