Created
July 17, 2019 06:23
-
-
Save Linusp/18f38937df6f2ddd9388c611af2d4e7e 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
_FUNCS = {} | |
def register(name): | |
def wrap(func): | |
global _FUNCS | |
if name not in _FUNCS: | |
_FUNCS[name] = func | |
else: | |
raise ValueError("name `{}` is already registered!".format(name)) | |
return func | |
return wrap | |
@register('f1') | |
def func1(params): | |
return params | |
@register('f2') | |
def func2(params): | |
return params | |
if __name__ == '__main__': | |
print(func1('hello')) | |
print(func1('world')) | |
print(_FUNCS) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment