Skip to content

Instantly share code, notes, and snippets.

@dominik-ba
Created November 9, 2018 14:50
Show Gist options
  • Save dominik-ba/2435d299136d80fcf460f14949036ec9 to your computer and use it in GitHub Desktop.
Save dominik-ba/2435d299136d80fcf460f14949036ec9 to your computer and use it in GitHub Desktop.
loads dynamically a method in python
class FunctionAttributeMapping(AttributeMapping):
def __init__(self, method, targetName):
AttributeMapping.__init__(self)
self.__method = method
self.__targetName = targetName
def getValue(self, ci):
import sys
modname = globals()['__name__']
module = sys.modules[modname]
method = self.__method
module = __import__(module)
return getattr(module, method)(ci)
def getTargetName(self):
return self.__targetName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment