开发者

Can XML-RPC methods be called by name (as strings) in Python?

开发者 https://www.devze.com 2023-01-31 11:11 出处:网络
In python, calling XML-RPC methods involves invoking methods on a proxy object: from xmlrpclib import ServerProxy

In python, calling XML-RPC methods involves invoking methods on a proxy object:

from xmlrpclib import ServerProxy
print ServerProxy('https://example.com/rpc').api.h开发者_StackOverflow社区ello_there('John')

In some other languages, like perl, you pass your method name as a method parameter.

use Frontier::Client;
$p = Frontier::Client->new(url => 'https://example.com/rpc');
$result = $p->call('api.hello_there', 'John');
print $result;

Is there a way to invoke XML-RPC methods by name, as strings, in Python?


Just use getattr, as with any Python object.

func = getattr(ServerProxy('https://example.com/rpc'), "api.hello_there")
print func('John')
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号