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)))
Transform source for micropython
The future-fstrings-show command can be used to transform source before
distributing. This can allow you to write f-string code but target platforms
which do not support f-strings, such as micropython.
To use this on modern versions of python, install using:
pip install future-fstrings[rewrite]
and then use future-fstrings-show as above.
For instance:
future-fstrings-show code.py > code_rewritten.py
How does this work?
future-fstrings has two parts:
- A utf-8 compatible
codecwhich performs source manipulation- The
codecfirst decodes the source bytes using the UTF-8 codec - The
codecthen leverages tokenize-rt to rewrite f-strings.
- The
- A
.pthfile which registers a codec on interpreter startup.
you may also like
Metadata
Release files for future-fstrings 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| future_fstrings-1.2.0.tar.gz | 5.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| future_fstrings-1.2.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 11.9 kB
Release files / future_fstrings-1.2.0.tar.gz
| Download URL | future_fstrings-1.2.0.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6cf41cbe97c398ab5a81168ce0dbb8ad95862d3caf23c21e4430627b90844089
|
|
BLAKE2b-256 checksum How to use checksums |
5de23874574cce18a2e3608abfe5b4b5b3c9765653c464f5da18df8971cf501d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.7
|
Release files / future_fstrings-1.2.0-py2.py3-none-any.whl
| Download URL | future_fstrings-1.2.0-py2.py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
90e49598b553d8746c4dc7d9442e0359d038c3039d802c91c0a55505da318c63
|
|
BLAKE2b-256 checksum How to use checksums |
ab6dea1d52e9038558dd37f5d30647eb9f07888c164960a5d4daa5f970c6da25
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.7
|
Security for future-fstrings 1.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.