The Python script
'''
a
'''
from __future__ import print_function
works well (i.e., does nothing), but
'''
a
'''
'''
b
'''
from __future__ import print_function
causes:
File "C:\test.py", line 8
from __future__ import print_function
SyntaxError: from __future__ imports must occur at the beginning of the file
Why?
https://docs.python.org/2/reference/simple_stmts.html#future says that:
A future statement must appear near the top of the module. The only lines that can appear before a future statement are:
- the module docstring (if any),
- comments,
- blank lines, and
- other future statements.
The second example only contains comments and blank lines before the from __future__ import print_function
, and yet it doesn't work.
I use Python 2.7.
所有评论(0)