4

在 python 中,调用 XML-RPC 方法涉及调用代理对象上的方法:

from xmlrpclib import ServerProxy
print ServerProxy('https://example.com/rpc').api.hello_there('John')

在其他一些语言中,例如 perl,您将方法名称作为方法参数传递。

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

有没有办法在 Python 中按名称(作为字符串)调用 XML-RPC 方法?

4

1 回答 1

3

只需使用getattr, 与任何 Python 对象一样。

func = getattr(ServerProxy('https://example.com/rpc'), "api.hello_there")
print func('John')
于 2010-12-21T18:23:21.393 回答