Skip to content

eval-md-py

This is an example of how to evaluate Python code snippets in a Markdown file, as if they were all part of a single script.

Bash
time bash main.sh README.md; echo $?

Example content

Preliminary steps:

Python
1
2
3
from lib import *

data = nest()

Now let's add some data:

Python
data['North America']['Q1']['Laptops'] = 125_000
data['North America']['Q1']['Phones'] = 98_500

data['North America']['Q2']['Laptops'] = 143_200

data['Europe']['Q1']['Laptops'] = 87_300
data['Europe']['Q1']['Phones'] = 65_900

data['Asia']['Q1']['Laptops'] = 192_000
data['Asia']['Q1']['Phones'] = 134_500

Finally, let's print the report:

Python
for line in tree_to_lines('TOTAL', data)[0]:
    print(line)