Skip to main content

Add your description here

Project description

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)

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'].

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

Acknowledgement

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

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

code_capture-0.1.0.tar.gz (1.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

code_capture-0.1.0-py3-none-any.whl (2.2 kB view details)

Uploaded Python 3

File details

Details for the file code_capture-0.1.0.tar.gz.

File metadata

  • Download URL: code_capture-0.1.0.tar.gz
  • Upload date:
  • Size: 1.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.18

File hashes

Hashes for code_capture-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f71d9420cfd8c63721b968a36fcb1add855714e83bc10ff8043c84fc0124d835
MD5 79752b3ccf02070f73b089a979d3060a
BLAKE2b-256 990bccdc04763d0325b929460edc17b5affd3d6f01d1ff76a61dbc110e63fca9

See more details on using hashes here.

File details

Details for the file code_capture-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for code_capture-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9959f7710a6b9fc657d0d680404d58a69a08df102cd484b2ad8e901c9e0e3188
MD5 6a1aa5b82d272f4fc1cb5404f3bafe7e
BLAKE2b-256 fd6038a9e8906a10838adce0c112104c1c001fa1dec25d8ca0262035c8451e2a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page