Advertisement
rfmonk

string_template.py

Dec 29th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.33 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import string
  4.  
  5. values = {'var': 'foo'}
  6.  
  7. t = string.Template("""
  8. Variable        : $var
  9. Escape          : $$
  10. Variable in text: ${var}iable
  11. """)
  12.  
  13. print 'TEMPLATE:', t.substitute(values)
  14.  
  15. s = """
  16. Variable        :   %(var)s
  17. Escape          :   %%
  18. Variable in text:   %(var)siable
  19. """
  20.  
  21. print 'INTERPOLATION:', s % values
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement