Skip to main content

Python 'f' Codec

Project description

Python f Codec

Wrap lonesome f-strings in print()

How to install

> python3 -m pip install f-codec

Why?

# -*- coding: f -*-

def dictionary(inst, level=0):
    indent = '    ' * level

    f''' {{
''' > indent

    for name, val in inst.items():
        if isinstance(val, dict):
            f'''
    {name} =
''' > indent
            dictionary(val, level + 1)
        else:
            f'''
    {name} = {val},
''' > indent

    f'''
}}
''' > indent

decl = {
    'a': 1,
    'b': 2,
    'c': { 'a': 3, 'b': 4 },
    'd': { 'a': 5, 'b': { 'a': 6, 'b': 7 }, 'c': 8},
    'e': 9
}

f'''
decl =
'''
dictionary(decl)
> python3 test.py

decl = {
    a = 1,
    b = 2,
    c = {
        a = 3,
        b = 4,
    }
    d = {
        a = 5,
        b = {
            a = 6,
            b = 7,
        }
        c = 8,
    }
    e = 9,
}

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

f-codec-0.0.5.tar.gz (2.9 kB view hashes)

Uploaded Source

Built Distribution

f_codec-0.0.5-py3-none-any.whl (4.4 kB view hashes)

Uploaded Python 3

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