A mini templating library
ChocExpr is used by Chocolatine to help to generate SQL queries, but you are free to use it for your own projects.
pip install choc-expr
- If-Then-Else statements
- Line break
- Compact/Extended mode
- Attributes evaluation :
- Loop : unpack iterable and join it by a character separator
- Attribute chain : follow the chain and return the nested value
- Nested Conditions
- Methods (upper, lower, title, etc...)
- Optional parenthesis in loop statement
from choc_expr import Expr as ChocExpr
age = 24 # or 15
print(ChocExpr("Kevin is @{age}>=18:an adult:a child; of {age} years old", vars()))
output :
>> Kevin is an adult of 24 years old
or
>> Kevin is a child of 15 years old
depending if condition is True or False.