Python:采用使用反射的web服务方法
你好! 我正在尝试使用反射的web服务方法。下面是一个代码示例:Python:采用使用反射的web服务方法,python,web-services,reflection,Python,Web Services,Reflection,你好! 我正在尝试使用反射的web服务方法。下面是一个代码示例: ... api = cf.SomeServiceAPI() #Test1 def test_SomeMethod(self): result = self.sender('SomeMethod', [setofvalue]) self.assertEqual(result, "Success", msg=result) def sender(self, methodname, setofvalue): re
...
api = cf.SomeServiceAPI()
#Test1
def test_SomeMethod(self):
result = self.sender('SomeMethod', [setofvalue])
self.assertEqual(result, "Success", msg=result)
def sender(self, methodname, setofvalue):
result = self.api.service.SomeMethod(setofvalue)
return result
请帮助我了解如何使用方法的名称应用该方法?
谢谢 看来这是问题的重复 你应使用:
getattr(object, 'method_name')
您可以使用getattr(clazzA,methodname)(setofvalue)
其中clazzA是对象,methodname是字符串中方法的名称,setofvalue是要传递到方法中的参数
以下是您请求的行为示例:
class A:
def some_method(self, arg):
print ("in: ", arg)
#Test1
def test_Some_method():
result = sender('some_method', "method")
def sender(methodname, setofvalue):
clazzA = A()
result = getattr(clazzA, methodname)(setofvalue)
return result
test_Some_method()
>>>'in: method'
我解决了这个任务
...
api = cf.SomeServiceAPI()
m1 = api.service.__getattr__('SomeMethod')
#Test1
def test_SomeMethod(self):
result = self.sender(self.m1, [setofvalue])
self.assertEqual(result, "Success", msg=result)
def sender(self, methodname, setofvalue):
result = method(setofvalue)
return result
谢谢如果我不知道模块的名称,这会起作用吗?只要对象具有具有此名称的属性,它就会起作用。谢谢!但是我没有显式的类A。所有方法都是在suds..px文件中定义的。它们的定义是使用wsdl自动完成的。