Skip to content

Instantly share code, notes, and snippets.

@keis
Created July 14, 2011 20:42
Show Gist options
  • Save keis/1083390 to your computer and use it in GitHub Desktop.
Save keis/1083390 to your computer and use it in GitHub Desktop.
python pretty formater
#!/usr/bin/env python
import re
split = re.compile(r'(%[A-Z][^%]|%[^%])').split
def format(s, values):
return ''.join([str(values[k[1:]]) if k.startswith('%') else k for
k in split(s)])
if __name__ == '__main__':
print format('%xtest%BaTEST%%', {
'x': 1234,
'Ba': 'zzz'})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment