Just curious, I tried from __future__ import *
, but I received this error:
File "<stdin>", line 1
SyntaxError: future feature * is not defined
Well, that makes sense. A __future__
import is a little special and doesn't follow the normal rules, but it got me to thinking: how can I import all the future features?
You can't, and that's by design. This is because more __future__
features might be added in the future, and those can break your code.
Imagine that in 2.x, the only __future__
feature was division
. Then in 2.y, a new __future__
feature, print_function
, is introduced. All of a sudden my code has broken:
from __future__ import *
print "Hello, World!"
You can, however, import __future__
, and inspect its contents:
>>> import __future__
>>> [x for x in dir(__future__) if x.islower() and x[0] != '_']
['absolute_import', 'all_feature_names', 'division', 'generator_stop', 'generators', 'nested_scopes', 'print_function', 'unicode_literals', 'with_statement']
Note that these are not features and you should not try to import them. They instead describe which features are available, and from which versions they are.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With