我有一个多播网络,需要连续发送数据给所有其他用户。这些数据会不断变化,所以我不希望程序员必须处理向用户发送数据包。因此,我试图找出如何在Python中引用任何对象或变量(我是Python的新手),以便用户可以修改它并更改多播包中发送的内容。Python中的参考文献
这里是我想要的一个例子:
>>> test = "test"
>>> mdc = MulticastDataClient()
>>> mdc.add(test) # added into an internal list that is sent to all users
# here we can see that we are successfully receiving the data
>>> print mdc.receive()
{'192.168.1.10_0': 'test'}
# now we try to change the value of test
>>> test = "this should change"
>>> print mdc.receive()
{'192.168.1.10_0': 'test'} # want 'test' to change to -> 'this should change'
我如何能解决这个问题的任何帮助将是非常赞赏。
UPDATE:
我也这样尝试过,以及:
>>> test = [1, "test"]
>>> mdc = MulticastDataClient()
>>> mdc.add(test)
>>> mdc.receive()
{'192.168.1.10_1': 'test'}
>>> test[1] = "change!"
>>> mdc.receive()
{'192.168.1.10_1': 'change!'}
该做的工作。 但是,
>>> val = "ftw!"
>>> nextTest = [4, val]
>>> mdc.add(nextTest)
>>> mdc.receive()
{'192.168.1.10_1': 'change!', '192.168.1.10_4': 'ftw!'}
>>> val = "different."
>>> mdc.receive()
{'192.168.1.10_1': 'change!', '192.168.1.10_4': 'ftw!'}
这是行不通的。我需要'ftw!'变得“不同”。在这种情况下。 我正在使用字符串进行测试,并使用字符串作为来自其他语言的对象。我只会编辑对象内部的内容,这样最终会起作用吗?
你是什么意思“我只会编辑对象内的内容“? – 2011-05-31 20:52:45
@rshallit所以如果我们有一个名为“pos”的位置对象,我只能操作pos.x和pos.y,您不必担心“pos”在内存中改变其位置。我想这对我来说是多余的。 – 2011-05-31 23:45:25