我正在尝试使 pyro4 代理可索引。为了测试这一点,我从http://pythonhosted.org/Pyro4/intro.html#simple-example中获取了问候示例并对其进行了修改:
服务器:
import Pyro4
class Test(object):
def __getitem__(self, index):
return index
test = Test()
print test[1]
print test[100]
daemon = Pyro4.Daemon()
uri = daemon.register(test)
print("Ready. Object uri =", uri)
daemon.requestLoop()
客户:
import Pyro4
uri = input("What is the Pyro uri of the object? ").strip()
test = Pyro4.Proxy(uri)
print test.__getitem__(1)
print test.__getitem__(100)
print test[1]
print test[100]
[] 符号适用于服务器,但不适用于客户端代理。我得到:
TypeError:“代理”对象不支持索引
但是直接打电话__getitem__
做工作。