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

Bill Janssen janssen at parc.com
Thu Sep 1 21:03:23 CEST 2005


I have to agree with Barry, Paul, Fredrik, Reinhold, etc. Removing the "print" statement would immediately break at a fundamental level 15 years of tutorials, books, and examples, many of which start with

print "Hello, World!"

Of course, maybe that's the idea -- this is not your father's Python! (Though that slogan apparently didn't work out so well for Oldsmobile...)

Is there a syntax trick here? Suppose start-of-the-line function names not followed by an open-paren, but followed by comma-separated lists of expressions, were treated as if the rest of the line were arguments to a function. That is, suppose

print "foo", 3, dir(sys)

was automagically converted to

print ("foo", 3, dir(sys))

Not sure I like this kind of trickyness, though. Though it might be useful for "assert", "raise", maybe "exec", too.

I also don't quite see the point of adding new top-level reserved words or built-in functions like "write". It clutters the namespace without being much of an improvement over "sys.stdout.write", IMO. Some kind of printf would be nice to have, but with Python's forgiving syntax is easy enough to add yourself.

Maybe the syntax used in the string.Template class is the way to go?

If you'd consider extending the Template syntax to positional parameters ($1, $2, etc.), then perhaps "print" could be modified to use the template for formatting, if it occurs as the first argument:

print string.Template("arg 1,arg1, arg 1,arg2"), arg1, arg2

with an alternate form

printf "arg 1,arg1, arg 1,arg2", arg1, arg2

where the first arg is required to be a template pattern string. This is a nice improvement over C printf in that you can re-use arguments.

What happens to Template() when the string module goes away? Do we write "arg 1,arg1, arg 1,arg2".Template() instead?

Bill



More information about the Python-Dev mailing list