Skip to main content

CodeCapture

CodeCapture is a context manager that enables capturing blocks of code while running it. This is meant for educational purposes, e.g., extracting blocks of code from a file for inclusion in readers.

>>> from code_capture import CodeCapture
>>> with CodeCapture("foo"):
        foo = 3
        bar = "test "
        foobar = foo * bar
        print(foobar)
test test test
>>> print(CodeCapture.store.foo)
foo = 3
bar = "test "
foobar = foo * bar
print(foobar)

Installation

pip install code-capture

Context manager

CodeCapture captures all code within the associated code block, based on the indentation of the code block.

Bunch

The capture code blocks are stored in the CodeCapture.store bunch. This allows for dot-access to the stored values. However, you can also treat CodeCapture.store as a dictionary, e.g., CodeCapture.store['foo'] equals CodeCapture.store.foo.

For more information, see https://pypi.org/project/bunch-py3/.

Acknowledgement

The code for this project was largely copied from Grayden's answer to this stackoverflow question.

Metadata

Release files for code-capture 0.1.4

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

Source distribution (sdist)

Source distribution for code-capture 0.1.4
File Size Uploaded Provenance Actions
code_capture-0.1.4.tar.gz 7.1 kB Without provenance Details for code_capture-0.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for code-capture 0.1.4
File Interpreter ABI Platform Actions
code_capture-0.1.4-py3-none-any.whl Python 3 none any Details for code_capture-0.1.4-py3-none-any.whl

Total release size: 13.3 kB

Release files / code_capture-0.1.4.tar.gz

Download URL code_capture-0.1.4.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
11dc964a1882f8146bbd88cd4bc65126351c0d661d75f746bf33b6fcb6bc079c
BLAKE2b-256 checksum
How to use checksums
95e82d512a6dd4be24a7446f56a7439585a7f85c35b26b2d5f37c12630bded15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.23

Release files / code_capture-0.1.4-py3-none-any.whl

Download URL code_capture-0.1.4-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
547359f98bbd09e37a1139678785d2795bfd9639272bcd178b59d84cea13690f
BLAKE2b-256 checksum
How to use checksums
8f35442dbb3987450743f047db4cf384d247d0976af8b741a0fc129eb74e794a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.23

Security for code-capture 0.1.4

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