from imp import *
def runMethod(className, methodName, args):
   # Get the module for the class.
    [file, pathName, desc] = find_module(className)
    module = load_module(className, file, pathName, desc)

    # Get an instance of the class.
    instance = eval("module." + className + "()")

    # Build the invocation string.
    invocationString = "instance." + methodName + "("
    if args == None:
      invocationString += ")"
    else:
      for arg in args:
        if type(arg) is int:
          invocationString += repr(int(arg))
        elif type(arg) is bool:
          invocationString += repr(bool(arg))
        elif type(arg) is str:
          invocationString += arg
        invocationString += ","

      # Get rid of the trailing comma and add the closing braces.
      invocationString = invocationString[:len(invocationString) - 1]
      invocationString += ")"

    # Invoke the method and return the result.
    try:
      result = eval(invocationString)
      return result
    except Exception, e:
      print "Oops, couldn't run method"

if __name__ == "__main__":
    runMethod("C", "foo", None) 


