Created
April 21, 2019 13:43
-
-
Save XayOn/ef43e7f5edb8657fd17bb2160193717f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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