Translate string formatting into Python 3.6-style string interpolation F-strings
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Translate string formatting into string interpolation

Python 3.6 introduces F-strings as a new way of doing string formatting.

Instead of writing this:

def say(greeting='hello', target='world'):
    print('%s, %s!' % (greeting.title(), target))

... you can now write this:

def say(greeting='hello', target='world'):
    print(f'{greeting.title()}, {target}!')

This project provides automatic translation of old %-style formatting to the new string interpolation method using F-strings.

Editor integration

If you use Vim, then simply source the fstrings.vim file. Select a set of lines (with V) and press = to update the selection.

If you use another editor, you can invoke the script as follows:

python3.6 40 50 < >

This parses all of and outputs just lines 40-50 to