Skip to content

Instantly share code, notes, and snippets.

@tdpearson
Last active November 30, 2017 19:54
Show Gist options
  • Select an option

  • Save tdpearson/9c126db5c03bbfa80d73d380f70d129a to your computer and use it in GitHub Desktop.

Select an option

Save tdpearson/9c126db5c03bbfa80d73d380f70d129a to your computer and use it in GitHub Desktop.
Jinja Int Padding Example
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