4
我有一個簡單的例子來送字典通過XML-RPC:XML-RPC - 不能元帥遞歸字典
class CTest(object):
def __init__(self):
self.node1 = {'data':'zek', 'parent':{}, 'children':[]}
self.node2 = {'data':'bill', 'parent':{}, 'children':[]}
self.node1['children'].append(self.node2)
self.node2['parent'] = self.node1
def getNode(self):
return self.node1
我有兩個字典:節點2是節點1的兒童,並在同一時間節點2將node1作爲父變量的引用。 所以它是一個遞歸字典。當我嘗試通過XML-RPC發送節點1,我得到這個異常:
#Command to execute xml-rpc dump method for serialization
test = CTest()
xmlrpclib.dumps((test,), 'Node Object')
#Exception
raise TypeError, "cannot marshal recursive dictionaries"
是否有可能通過XML-RPC發送節點1(不改變字典結構)?
謝謝。
感謝。它與cPickle完美配合。但它需要與語言無關。 因此,當我在一個對等體上醃製字典時,我還需要在其他對等體中使用python來取消它。 因爲我以xml格式發送字典,所以通常可以在另一個同位體(C,C++,java)中使用另一種編程語言。 這就是爲什麼我不能使用pickle。 Pyro有它自己的網絡通信代碼,它不使用XML-RPC。我需要使用XML-RPC。 那麼你知道任何其他的方法來發送這本字典通過XML-RPC沒有泡菜嗎? – zekifh 2011-05-24 13:29:07