[Python-Dev] Replacement for print in Python 3.0

Guido van Rossum guido at python.org
Thu Sep 1 22:15:03 CEST 2005

On 9/1/05, Fredrik Johansson <fredrik.johansson at gmail.com> wrote:
> Why not instead change the language so as to allow any function call
> to be written without parentheses (when this is unambiguous)? This
> could make Python more convenient for creating imperative-style DSLs
> (though I'm not sure this is a goal).

Given all the other syntax it would be too ambiguous. If you really
want this, please sit down and design a grammar. If you can't do that,
just believe me that it would be too nasty (with too many exceptional
cases) to bother.

> In any case, I think "write" would be better than "print", because it
> is easier to type (at least for me; reaching for 'w' and than 'r' goes
> much faster than reaching for 'p'). I don't like "writeln" though, as
> in 9 of 10 cases I want the line break to be there. I'd rather have
> write add the line break, and "writeraw" or somesuch exclude it.

Yuck. Also, write() and writeln() have a long history going back to
Pascal. Java has print() and println(). Plus stream.write("abc")
already has a meaning, and the elegance of my proposal is that that
meaning remains unchanged.

> By the way, if print has to go, then what about the assert, raise, and
> import statements? Should these be changed to use function call syntax
> as well? (By the way, assert and raise could be methods:
> ZeroDivisionError.assert(denom != 0). Surprising that Java doesn't do
> this ;-)

It can't work for import because it defines a new name; if import were
a function, then import(foo) would necessarily mean to evaluate foo
first, which isn't what you want.

It could work for raise (and even for break and continue) but I'd
rather keep control flow as statements; you never know what the
compiler could do with the information that a particular block doesn't
contain a raise statement.

It can't work for assert because you don't want the argument to be
evaluated in -O mode.

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

More information about the Python-Dev mailing list