[Python-Dev] Replacement for print in Python 3.0 (original) (raw)

Guido van Rossum guido at python.org
Thu Sep 1 22:07:39 CEST 2005


On 9/1/05, Bill Janssen <janssen at parc.com> wrote:

After reviewing the PEP 3000 notes, I can find no justification there for removing "print" other than your statement here -- that it has served honorably and well in many programming languages for many years, a curious reason for abandoning it.

Some reasons to drop it have to do with the arcane syntax: (a) the trailing comma (is there anyone who likes that?), and (b) the optional ">>file" part. While I've always defended the latter against powerful opposition, that was only because print was already a statement and I find it important to have a way to do whatever print does to an arbitrary file. Of course, if print() were a function, we wouldn't need special syntax, we could just use stream.print() with the same signature; so that's one argument for dropping the syntax.

Another real problem with print is that, while the automatic insertion of spaces is nice for beginners, it often gets in the way, and what you have to do to avoid this is pretty nasty: either drop print altogether in favor of sys.stdout.write(), or use string concatenation or a format string, assuming you have all the pieces available at the same time (which often you don't). Surely you don't want to suggest an extension, for example doubling the comma could make the extra space go away... :-)

It looks to me like most arguments for keeping print are motivated by backwards compatibility (in its many guises, like the existence of 15 years of tutorials) and not by what would be best if we were to design a language from scratch.

It seems to me that, as long as write() and writeln() were built-ins taking multiple args, teaching a beginner to use

writeln("The answer is: ", 4+4)

is perfectly clear (and might be a gentle introduction to function calls as well).

I've been thinking about some ancient Python history recently, which reminded me that one theme in Python's design is to have a minimalist syntax without being syntax-free like Lisp. (In a very early version of Python, 'dir' was a statement, just so that I wouldn't have to type the parentheses. Glad I dropped that one!) I really believe that dropping print in favor of a few built-in functions is an improvement -- backwards compatibility be damned!

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



More information about the Python-Dev mailing list