Skip to content

Instantly share code, notes, and snippets.

@Linusp
Created July 17, 2019 06:23
Show Gist options
  • Save Linusp/18f38937df6f2ddd9388c611af2d4e7e to your computer and use it in GitHub Desktop.
Save Linusp/18f38937df6f2ddd9388c611af2d4e7e to your computer and use it in GitHub Desktop.
_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