Last active
November 30, 2017 19:54
-
-
Save tdpearson/9c126db5c03bbfa80d73d380f70d129a to your computer and use it in GitHub Desktop.
Jinja Int Padding Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from jinja2 import Environment | |
| mytemp = """ | |
| my box number is {{ "%(box)04d"|format(box=mybox) }} | |
| """ | |
| print Environment().from_string(mytemp).render(mybox=456) | |
| # my box number is 0456 | |
| print Environment().from_string(mytemp).render(mybox=3) | |
| # my box number is 0003 | |
| print Environment().from_string(mytemp).render(mybox=1234) | |
| # my box number is 1234 | |
| print Environment().from_string(mytemp).render(mybox=12345) | |
| # my box number is 12345 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment