0

There's a well-known joke in Python regarding braces. But - how does it work?

When I search the source file, I can't find anything about braces:

$ python2.7
python2.7
Python 2.7.10 (default, Feb  7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import braces
  File "<stdin>", line 1
SyntaxError: not a chance
>>> import __future__
>>> __future__.__file__
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/__future__.pyc'
>>>
zsh: suspended  python2.7
$ grep 'braces' /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/__future__.py
[no response]
scubbo
  • 4,969
  • 7
  • 40
  • 71
  • 2
    None of the `__future__` imports are implemented in `__future__.py`. – user2357112 Sep 05 '18 at 05:44
  • `__future__` imports are compiler directives. It's completely impossible to implement those features in a python module. `__future__` has to be built into the compiler. – Aran-Fey Sep 05 '18 at 05:49
  • Interesting - thanks! – scubbo Sep 05 '18 at 06:11
  • another dupe: [what-is-future-in-python-used-for-and-how-when-to-use-it-and-how-it-works](https://stackoverflow.com/questions/7075082/what-is-future-in-python-used-for-and-how-when-to-use-it-and-how-it-works) - Python.org reference: [future-statements](https://docs.python.org/3/reference/simple_stmts.html#future-statements) – Patrick Artner Sep 05 '18 at 10:21

0 Answers0