0

変数をコピーして変更する必要があります。私はすでにこれを見てきましが、私は反対が欲しいです。このコードでは、返されるタプルが同じではなく、2つの異なるリストである必要があります。

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
4

1 に答える 1

0

最も一般的なのはおそらく

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

これは、self.ipの要素から新しいリストを作成します。または、 Pythonのコピーユーティリティを使用することもできます

于 2013-02-12T20:14:42.177 に答える