Skip to content

Instantly share code, notes, and snippets.

@Tattoo
Created July 20, 2016 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tattoo/62f246988df68650ccd19f4f298c9ecb to your computer and use it in GitHub Desktop.
Save Tattoo/62f246988df68650ccd19f4f298c9ecb to your computer and use it in GitHub Desktop.
from inspect import getargspec
from types import FunctionType
from your_module import (a_method
another_method,
and_so_on)
class ExampleDynamicLibrary(object):
def __init__(self):
self.keywords = {}
for name, method in globals().items():
if (isinstance(method, FunctionType) and
method.__module__ == 'your_module'):
self.keywords[name] = method
def get_keyword_names(self):
return self.keywords.keys()
def run_keyword(self, name, arguments, kwargs):
return self.keywords[name](arguments, kwargs)
def get_keyword_arguments(self, name):
argspec = getargspec(self.keywords[name])
args = argspec.args
if argspec.varargs:
args = args.append('*' + argspec.varargs)
if argspec.keywords:
args = args.append('**' + argspec.keywords)
return args
def get_keyword_documentation(self, name):
if '__intro__':
return self.__doc__
return self.keywords[name].__doc__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment