3

We had from __future__ import print_function in 2.7, so could we have from __future__ import formatted_string_literals in, say, 3.4 and 3.5 (maybe even 2.7)?

Is there some policy that prohibits this, some technical reason, or just nobody got around tuit yet?

Ref: PEP 498: Formatted string literals

frnhr
  • 12,354
  • 9
  • 63
  • 90
  • `__future__` imports are generally for things that will change the behaviour of existing code, not just to backport new features. Currently `f'whatever'` is a syntax error, so there isn't code out there using it, unlike e.g. changing the behaviour of `/` or `print`. And [*"Python 2.7 will never support f-strings"*](https://www.python.org/dev/peps/pep-0498/#can-t-combine-with-u). – jonrsharpe Nov 27 '16 at 15:03
  • Or for new keywords: [*"`yield` is a new keyword, so a future statement is needed to phase this in"*](https://www.python.org/dev/peps/pep-0255/). – jonrsharpe Nov 27 '16 at 15:09

2 Answers2

4

from __future__ imports are used to introduce incompatible changes, f-strings are a new feature and not a breaking change.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Daniel
  • 42,087
  • 4
  • 55
  • 81
3

Bringing f-strings to Python less than 3.6 is now covered at https://stackoverflow.com/a/46182112/8508004 . It is done via future-fstrings and simply requires a special line at the top of your code.

(I wanted to comment above but couldn't yet due to reputation restrictions for that.)

Wayne
  • 6,607
  • 8
  • 36
  • 93