我想讓一個pyro4代理索引。爲了驗證這一點,我把問候例如從http://pythonhosted.org/Pyro4/intro.html#simple-example,我修改了它:使pyro4代理索引
服務器:
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: 'Proxy' object does not support indexing
但直接調用__getitem__
確實有效。
這確實有效。但是我在Pyro中看到了Python本身的問題。我期望[0]只是一個圍繞a._ getitem _(0)的句法加糖。相反,似乎有代碼檢查字典中是否存在_ getitem _。而這可能只是爲了讓錯誤消息fancier:object不可轉位,而不是_ getitem _未定義。 – andi