Advertisement
rfmonk

string_template_missing.py

Dec 29th, 2013
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.30 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import string
  4.  
  5. values = {'var': 'foo'}
  6.  
  7. t = string.Template("$var is here but \
  8.                    $missing is not provided")
  9.  
  10. try:
  11.     print 'substitute() t.substitute(values):',
  12. except KeyError, err:
  13.     print 'ERROR:', str(err)
  14.  
  15. print 'safe_substitute():',
  16. t.safe_substitute(values)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement