Skip to content

Instantly share code, notes, and snippets.

@XayOn
Created April 21, 2019 13:43
Show Gist options
  • Save XayOn/ef43e7f5edb8657fd17bb2160193717f to your computer and use it in GitHub Desktop.
Save XayOn/ef43e7f5edb8657fd17bb2160193717f to your computer and use it in GitHub Desktop.
class Formatter:
pass
class DefaultFormatter(Formatter):
name = "default"
def format(string):
return string
class UpperFormatter(Formatter):
name = "bar"
def format(string):
return string.upper()
formatters = dict({a.name: a for a in Formatter.__subclasses__()})
do_format = lambda string, formatter="default": formatters.get(formatter).format(string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment