[Python-ideas] A suggestion for Python 3 vs Python 2

anatoly techtonik techtonik at gmail.com
Wed Nov 13 20:55:27 CET 2013


On Wed, Nov 13, 2013 at 10:22 PM, אלעזר <elazarg at gmail.com> wrote:
> 2013/11/13 anatoly techtonik <techtonik at gmail.com>:
>> So, what's wrong with supporting both:
>> 1. print xxx   - as a statement (which maps to function call)
>> 2. print(xxx)  - as an expression (which is a function call)
>>
>
> Python2:
>>>> print (1,2)
> (1, 2)
>
> Python3:
>>>> print (1,2)
> 1 2

That's horrible. Ok, I agree - this is the reason why it might be
impossible to make both statement and a function. But between two
ambiguities I chose that the function syntax takes precedence, because
"print xxx" is a limited helper for fast-typing, with well-known
limitations. More arguments - I doubt people often print tuples
without formatting, and even if they do this, it is the code that they
usually read immediately and can spot the mistake, so it doesn't hurt.
It is not beautiful to have such ambiguity, and may not be
recommended, and still "print xxx" is a nice feature to have.

> What is your suggestion? Repeat Ruby's failure to make function call
> whitespace-insensitive?

I don't know Ruby. Where I can read more about this Ruby's fail?

>>>> print(1,2)
> 1 2
>>>> print (1,2)
> (1,2)
>
> That's horrible.

They should both map to print as expression, meaning print as a
function, i.e. to the first one.

> Besides, how do you want code like this one to behave?
>
>>>> print = log
>>>> print xxx

"print xxx" translates to simplified print() call on the language level.

> Or this:
>
>>>> import builtins
>>>> builtins.print = log
>>>> print xxx

The same. When you get AST, it is already print call, or the statement
can be translated to expression just after AST is received.


More information about the Python-ideas mailing list