Is this supposed to work in Python 3.4:
>>> a='tttt'
>>> print(f'The value of a is {a}')
I wrote a (terrible) thing that enables them via an encoding trick:
First:
pip install future-fstrings
and then replace the encoding cookie (if you have one) and bam! f-strings in python<3.6
# -*- coding: future_fstrings -*-
thing = 'world'
print(f'hello {thing}')
Runtime:
$ python2.7 main.py
hello world
No, f
strings were introduced in Python 3.6 which is currently (as of August 2016) in alpha.
You could at least emulate them if really needed
def f(string):
# (!) Using globals is bad bad bad
return string.format(**globals())
# Use as follows:
ans = 'SPAM'
print(f('we love {ans}'))
Or maybe some other ways, like a class with reloaded __getitem__
if you like f[...] syntax
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