{"id":15009462,"url":"https://github.com/damnever/fmt","last_synced_at":"2026-02-23T22:17:15.595Z","repository":{"id":57431628,"uuid":"69169532","full_name":"damnever/fmt","owner":"damnever","description":"Using f-strings(PEP 498) style literal string interpolation without Python 3.6.","archived":false,"fork":false,"pushed_at":"2017-01-19T14:20:50.000Z","size":37,"stargazers_count":14,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-23T19:38:38.388Z","etag":null,"topics":["f-strings","format","pep498","python-3-6"],"latest_commit_sha":null,"homepage":"https://git.io/vDxS7","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/damnever.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-25T14:33:37.000Z","updated_at":"2024-11-11T08:59:11.000Z","dependencies_parsed_at":"2022-09-02T11:51:48.647Z","dependency_job_id":null,"html_url":"https://github.com/damnever/fmt","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damnever%2Ffmt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damnever%2Ffmt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damnever%2Ffmt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damnever%2Ffmt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/damnever","download_url":"https://codeload.github.com/damnever/fmt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248075668,"owners_count":21043631,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["f-strings","format","pep498","python-3-6"],"created_at":"2024-09-24T19:25:25.114Z","updated_at":"2026-02-23T22:17:15.520Z","avatar_url":"https://github.com/damnever.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"f-strings(Python 3.6) style literal string interpolation.\n==========================================================\n\n.. image:: https://img.shields.io/travis/damnever/fmt.svg?style=flat-square\n    :target: https://travis-ci.org/damnever/fmt\n\n.. image:: https://img.shields.io/pypi/v/fmt.svg?style=flat-square\n    :target: https://pypi.python.org/pypi/fmt\n\n\nUsing `f-strings(PEP 498) \u003chttps://www.python.org/dev/peps/pep-0498/\u003e`_ style literal string interpolation without Python 3.6.\n\n\nUsages\n------\n\n- Accessing the globals and locals.\n\n    .. code:: python\n\n        import os\n        import fmt as f\n\n        g_foo = 'global-foo'\n        g_bar = 'global-bar'\n        g_num = 23\n        g_ls = [1, 2, 3]\n\n        def scope():\n            l_foo = 'local-foo'\n            l_bar = 'local-bar'\n            print( f('{l_foo}, {l_bar}') )    # 'local-foo, local-bar'\n            print( f('{g_foo}, {g_bar!r}') )  # \"global-foo, 'global-bar'\"\n\n        scope()\n        print( f('{{ }}') )                   # '{ }'\n        print( f('hex: {g_num:#x}') )         # '0x17'\n        print( f('{os.EX_OK}') )              # '0'\n        print( f('{g_ls[0]}, {g_ls[1]}, {g_ls[2]}') )  # '1, 2, 3'\n\n\n- **NOTE**: **Closure** will be a little tricky, must pass the outside scope variables as arguments to f,\n  which added a reference to inside the closure in order this can work.\n\n    .. code:: python\n\n        import fmt as f\n\n        def outer(x='xx'):\n            y = 'yy'\n            def inner():\n                print( f('{x}, {y}', x, y) )  # \"xx, yy\"\n            return inner\n\n        outer()()\n\n\n- Expression evaluation.\n\n    .. code:: python\n\n        from datetime import datetime\n        import fmt as f\n\n        class S(object):\n            def __str__(self):\n                return 'hello'\n            def __repr__(self):\n                return 'hi'\n            def __format__(self, fmt):\n                return 'abcdefg'[int(fmt)]\n\n        print( f('{1234567890:,}') )             # '1,234,567,890'\n        print( f('{1 + 2}') )                    # '3'\n        print( f('{str(1 + 2)!r}') )             # \"'3'\"\n        print( f('{[i for i in range(5)]}') )    # '[0, 1, 2, 3, 4]'\n        ls = range(5)\n        print( f('{{i for i in ls}}') )          # 'set([0, 1, 2, 3, 4])' or '{0, 1, 2, 3, 4}'\n        print( f('{{k:v for k,v in zip(range(3), range(3, 6))}}') )  # '{0: 3, 1: 4, 2: 5}'\n        print( f('{datetime(1994, 11, 6):%Y-%m-%d}') )               # '1994-11-06'\n        print( f('{list(map(lambda x: x+1, range(3)))}') )           # '[1, 2, 3]'\n        print( f('{S()!s}, {S()!r}, {S():1}') )                      # 'hello, hi, b'\n\n\n- Also, you can register some namespaces for convenience.\n\n    .. code:: python\n\n        import fmt as f\n\n        f.mregister({'x': 1, 'y': 2})  # register multiple\n        f.register('z', 3)             # register only one\n\n        def func(x, y):\n            return x + y\n\n        print( f('{func(x, y)}') )  # '3'\n        print( f('{func(x, z)}') )  # '4'\n        print( f('{func(y, z)}') )  # '5'\n\n\n- **NOTE**: ``locals()`` maybe cover the ``globals()``, ``globals()`` maybe cover the namespaces that you registered.\n\n\nInstallation\n------------\n\nInstall by pip: ::\n\n    [sudo] pip install fmt -U\n\n\nLICENSE\n-------\n\n`The BSD 3-Clause License \u003chttps://github.com/damnever/fmt/blob/master/LICENSE\u003e`_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdamnever%2Ffmt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdamnever%2Ffmt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdamnever%2Ffmt/lists"}