Python preprocessor
Run python code inside files
view on
github

About

The pyp application functions similar to how PHP functions, except it uses python and is designed for stand-alone file processing.

Arbitrary python code can be placed in <? python_code; ?> tags, and then running pyp input.txt output.txt will process the input file into a new output file.

Required software

Downloads

Current downloads are for Windows, and work on Windows 7 x86/x64.
Note: rename the file you download to pyp.exe for ease of use.

For extra build versions, check out the bin directory

Tag syntax

There are two forms of tags that can be used: execution tags and evaluation tags.

Tag continuations

Tag continuations are used to turn text content outside of tag blocks into a string to be used in an expression. They can be used with both execution tags and evaluation tags.

Tag continuations are formed by adding an ellipsis ... to the starting/ending tags surrounding the content to be stringified. For example, the following are identical:

<? use_code( ...?>convert this to a string<?... ); ?>
<? use_code("convert this to a string"); ?>

There can also be nested tags, albeit not usually necessary:

<? use_code( ...?>convert <?="this"?> to a string<?... ); ?>
<? use_code( ...?>convert this to a string<?... ); ?>
<? use_code("convert this to a string"); ?>

Invalid, mismatched, or differing type tag continuations will all result in an error.

pyp module

For code evaluation, a python variable called pyp is added into the global scope. It represents a module which has two functions: write and include.

Command line

The pyp command line is simple and provides a few customization options. The basic style of the command line can be one of the following:

pyp <args> INPUT.txt OUTPUT.txt
pyp <args> -iINPUT.txt -oOUTPUT.txt
pyp <args> -i INPUT.txt -o OUTPUT.txt
pyp <args> --input INPUT.txt --output OUTPUT.txt

Command line arguments

Additional info can be obtained by executing pyp --usage.