2
在Python中,調用XML-RPC方法涉及到一個代理對象上調用方法:在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方法?
您不能使用帶有虛線名稱的getattr;認爲你需要getattr(getattr(...,'api'),'hello_there')。 – 2010-12-21 18:33:15