Skip to content

Instantly share code, notes, and snippets.

@offby1
Created June 1, 2015 04:34
Show Gist options
  • Select an option

  • Save offby1/ff91f16aeeac05ceaa09 to your computer and use it in GitHub Desktop.

Select an option

Save offby1/ff91f16aeeac05ceaa09 to your computer and use it in GitHub Desktop.
import string
class Template(string.Formatter):
def format_field(self, value, spec):
if spec.endswith('h'):
value = str(value) # ultimately, this will call a funtion that will format the value and return as string
spec = spec[:-1] + 's'
return super(Template, self).format_field(value, spec)
f= Template()
print(f.format("Hello {:h}", "world"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment