我需要复制一个变量并对其进行更改。我已经见过this了,但我想要那个对立面。在这段代码中,我需要返回的元组是两个不同的列表,而不是相同的列表。
def getIPRange(self):
group = [0, self.getJoinedNetworks() - 1]
while True:
if self.ip[2] > group[0] and self.ip[2] < group[1]:
res_ip_min = self.ip #self.ip is for example [70, 30, 20, 0]
res_ip_min[2] = group[0]
res_ip_min[3] = 1
res_ip_max = self.ip
res_ip_max[2] = group[1]
res_ip_max[3] = 254
return (res_ip_min, res_ip_max)
else:
group[0] = group[1] + 1
group[1] = group[0] + self.getJoinedNetworks() - 1发布于 2013-02-13 04:14:42
最常见的可能是这样做
...
res_ip_min = list(self.ip)
...
res_ip_max = list(self.ip)
...它从self.ip的元素创建一个新的列表。或者,您可以使用python's copy utilities
https://stackoverflow.com/questions/14839954
复制相似问题