Skip to main content

A backport of fstrings to python<3.6

Project description

Build Status Azure DevOps coverage

future-fstrings

A backport of fstrings to python<3.6.

Installation

pip install future-fstrings

Usage

Include the following encoding cookie at the top of your file (this replaces the utf-8 cookie if you already have it):

# -*- coding: future_fstrings -*-

And then write python3.6 fstring code as usual!

# -*- coding: future_fstrings -*-
thing = 'world'
print(f'hello {thing}')
$ python2.7 main.py
hello world

Showing transformed source

future-fstrings also includes a cli to show transformed source.

$ future-fstrings-show main.py
# -*- coding: future_fstrings -*-
thing = 'world'
print('hello {}'.format((thing)))

How does this work?

future-fstrings has two parts:

  1. A utf-8 compatible codec which performs source manipulation
    • The codec first decodes the source bytes using the UTF-8 codec
    • The codec then leverages tokenize-rt to rewrite f-strings.
  2. A .pth file which registers a codec on interpreter startup.

you may also like

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

future_fstrings-1.0.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

future_fstrings-1.0.0-py2.py3-none-any.whl (6.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file future_fstrings-1.0.0.tar.gz.

File metadata

  • Download URL: future_fstrings-1.0.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

File hashes

Hashes for future_fstrings-1.0.0.tar.gz
Algorithm Hash digest
SHA256 28a926ad769e1ff7f887bc4135921c42f4da570eab6d5e34cb366663e3182adf
MD5 ccae6e9dbfeddca0812b9b6d1f00af75
BLAKE2b-256 1a819485489b0adeb0a8a49482fde0bcccb9b71a6074de14b6457fb39b91c370

See more details on using hashes here.

Provenance

File details

Details for the file future_fstrings-1.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: future_fstrings-1.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

File hashes

Hashes for future_fstrings-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 928aac9e1879a9fc49b8d873cae4638ce5a70673a79199a9e3b97c821a61de11
MD5 7158ce9fb22e27ac11879785d9cafb44
BLAKE2b-256 d510de62670513b7b2e7de32bbabb662cbc05ccee49fadf6f69725388df780e8

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page