Skip to main content

ScopeFormatter allows Python’s string formatting to be used with names drawn from the current scope, similar to the variable interpolation found in languages such as Ruby and Perl.

Examples

>>> from scopeformatter import F
>>> greeting = 'Hello'
>>> def greet(name):
...     return F('{greeting}, {name}!')
>>> greet('world')
'Hello, world!'

Positional and keyword arguments are accepted:

>>> F('{greeting} {0} times, {name}!', len(greeting), name='world')
'Hello 5 times, world!'

Requirements

The stack inspection requires a Python VM that provides sys._getframe(), such as CPython.

Limitations

Non-global names from enclosing scopes will not be found unless they are referenced in the local scope.

>>> def outer():
...     non_local = 'non-local'
...     def inner():
...         return F('{non_local} is not referenced locally')
...     return inner()
>>> outer()
Traceback (most recent call last):
    ...
KeyError: 'non_local'
>>> def outer():
...     non_local = 'non-local'
...     def inner():
...         non_local
...         return F('{non_local} is referenced locally')
...     return inner()
>>> outer()
'non-local is referenced locally'

History

1.0.3 – 2009 Oct 22

  • Added history to the project page.

  • Added additional documentation files.

1.0.2 – 2009 Oct 22

  • Reorganized metadata.

  • Removed dependencies on setuptools and nose.

1.0.1 – 2009 Oct 3

  • Made minor additions to metadata.

1.0 – 2009 Sept 25

  • Initial release.

Metadata

Release files for ScopeFormatter 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ScopeFormatter 1.0.3
File Size Uploaded Provenance Actions
ScopeFormatter-1.0.3.tar.gz 3.1 kB Without provenance Details for ScopeFormatter-1.0.3.tar.gz

Release files / ScopeFormatter-1.0.3.tar.gz

Download URL ScopeFormatter-1.0.3.tar.gz
Size 3.1 kB
Tags Source
SHA-256 checksum
How to use checksums
73b60fb05eb93e71bef119840b70d88c358136450a466bfd5d471b8b148598a8
BLAKE2b-256 checksum
How to use checksums
2fa7238ff037ae2be90a1cf77db1962a318287e6e0f610a4e9847c704e25f395
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for ScopeFormatter 1.0.3

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page