f-string debugging shorthand in Python 3.6

Viewed 395

The following works in Python 3.8+

a = 1.5
print(f'{a=}')

In earlier Python versions it is equivalent to

a = 1.5
print(f'a={a}')

I developed my library for Python 3.8+ but a few servers (CentOS-7, OpenSUSE-15.1/15.2) have Python 3.6 by default, where this library is to be deployed. I can install 3.8 on these servers as last resort or rewrite f-string lines.

I was wondering if there is any from __future__ import xxx trick or a third party library that backports this to 3.6.

1 Answers

Here you go: https://github.com/MegaIng/python-magic/tree/master/encoding_magic

While I don't really recommend using this kind of code in production, this implements what you want for python3.6.

Note that this package isn't published on pypl since it would be problematic to install it correctly without manual setup afterwards.

This works the same as the other package you point me to, but it doesn't allow fstrings to work in versions < 3.6, only implements the = for python3.6.

Related