Automatically convert old string formatting style into f-strings

Use flynt. You call it with the name of directory and it recursively searches for all .py files and converts % formatting to f-strings.

flynt <directory_to_process>

It will convert .format() calls as well as % formatting.

You can install it with

pip install flynt

Be warned that converting % to f-strings is not perfect and will have different results if you were passing a single element tuple into them (which is why Python moved away from % formatting).


Use pyupgrade. Specifically, to enable converting to f-strings, use

pyupgrade --py36-plus <filename>

You can install it with

pip install pyupgrade