Hacker News new | past | comments | ask | show | jobs | submit login

For example, "x = print" is invalid syntax in Python2.6, unless you include "from __future__ import print_function" at the beginning of the file.

Well, you're not changing any syntax there. Print moves from a statement in 2.6 to a function in 3.x, and if it's a function you can just assign it like any other function. In other words, after doing "x = print" you still could not call "x 'hello world'", you'd have to use "x('hello world')".

(not that I disagree with your overall argument)




Statements and expressions are different syntactic elements. So "x = print" will throw a syntax error in 2.6:

    >>> x = print
      File "<stdin>", line 1
        x = print
                ^
    SyntaxError: invalid syntax
But not if you "from __future__ import print_function" first. This is also why __future__ imports need to be at the very top of each file they are included in (unlike other imports).


Ah yes, apologies, I completely misunderstood your statement.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: