Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

future-fstrings

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

future-fstrings

A backport of fstrings to python<3.6

  • 1.2.0
  • PyPI
  • Socket score

Maintainers
1

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)))

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:

  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

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc