TWPS: (T)ext (W)ith (P)ython (S)nippets preprocessor
Project description
A python package to preprocess text files with embedded Python code snippets: evaluate or execute them and replace with the result of evaluation/execution.
This package provides the ppp.py script. The script reads the file specified in the command line, finds python snippets, evaluates or executes them and writes out the file with the pyhton code replaced with the evaluateion/execution result.
The following example shows a template file (i.e. the file to be processed with ppp.py) and the result.
Template (test/t1.t) |
Resulting file (test/t1.res.t) |
---|---|
`` The characters on the 1-st line define the delimiters, used to mark the python snippets. In this case, both the begin of the snippet and its end are denoted with the backtick. This is an evaluation snippet: `2*7`, and this is an execution snippet: `from math import pi; pi2=pi*2`. Check that the definitions made in the previous snippets are accessible: `pi2`. |
The characters on the 1-st line define the delimiters, used to mark the python snippets. In this case, both the begin of the snippet and its end are denoted with the backtick. This is an evaluation snippet: 14, and this is an execution snippet: `from math import pi; pi2=pi*2`. Check that the definitions made in the previous snippets are accessible: 6.28318530718. |
Install
The package is published on PyPI: https://pypi.org/project/twps/. The preffered way to install is:
>pip install twps
Getting help
For command line options see readme.rst in the twps folder or run the script without command line arguemnt.
General description with examples (somewhat outdated) can be found in the docs folder.
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
File details
Details for the file twps-2.0.4.tar.gz
.
File metadata
- Download URL: twps-2.0.4.tar.gz
- Upload date:
- Size: 71.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25796bdebed019e3e8bc53614bcd57efcdad23c1e87464841feca9957bda042c |
|
MD5 | 96a4be5deddf9ed106c49cc0630b9dfe |
|
BLAKE2b-256 | ff2e386da522afb486a27770ff6799e814de31f0d5690fba4004fa39d3ad3715 |