On 9/1/05, Guido van Rossum <[EMAIL PROTECTED]> 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! > > 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/)
There is a lot of debate over this issue, obviously. Now, I think getting rid of the print statement can lead to ugly code, because a write function would be called as an expression, so where we'd once have prints on their own lines, that wouldn't be the case anymore, and things could get ugly. But, print is a little too inflexible. What about adding a special name __print__, which the print statement would call? It should be looked up as a local first, then global. Thus, different parts of a program can define their own __print__, without changing everyone else's stdout. The Python web people would love that. _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com