2013-02-12 55 views
0

我需要复制一个变量并对其进行更改。 我已经看过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 

回答

0

最常见的可能是做

... 
res_ip_min = list(self.ip) 
... 
res_ip_max = list(self.ip) 
... 

它创建从self.ip.的元素的新列表或者你可以使用python's copy utilities

+0

我要去试试。谢谢 – gcq 2013-02-12 20:15:43