Why are 2 variables being modified here? /u/Dragonmanenderr Python Education

Sorry in advance for the long explanation.

Background for this code: i am trying to make a QR code generator. Part of the process is to have 2 polynomials, the generator and the message polynomial (represented as lists of alpha notation). I wont go into full depth about how this works, but basically when dividing one polynomial by the other, the first step is to multiply all the terms in the generator polynomial by the first term of the message polynomial. In my code, this works the 1st time, but not again.

for i in range(self.QRsize.QRversionList[self.QRversion-1][self.QRspecs[3]]): self.newGeneratorPolynomial = [] self.newGeneratorPolynomial = self.generatorPolynomial for j in range(len(self.newGeneratorPolynomial)): a = int(self.newGeneratorPolynomial[j][2:]) b = self.alpha.decToAlpha[str(self.messagePolynomial[0])] c = self.alpha.alphaToDec['a_' + str((a + b) % 255)] self.newGeneratorPolynomial.pop(j) self.newGeneratorPolynomial.insert(j, c) ~~~more code here before looping back~~~ 

From my testing, the problem seems to be that the ‘j’ loop modifies ‘self.generatorPolynomial’ and ‘self.newGeneratorPolynomial’ at the same time. What is meant to happen is that ‘self.generatorPolynomial’ is always the same, then ‘self.newGeneratorPolynomial’ copies its data, and that is the one that is modified. Every iteration in the loop should start off by resetting the generator polynomial to what it was, but it isnt doing that.

Any help is appreciated!

submitted by /u/Dragonmanenderr
[link] [comments]

​r/learnpython Sorry in advance for the long explanation. Background for this code: i am trying to make a QR code generator. Part of the process is to have 2 polynomials, the generator and the message polynomial (represented as lists of alpha notation). I wont go into full depth about how this works, but basically when dividing one polynomial by the other, the first step is to multiply all the terms in the generator polynomial by the first term of the message polynomial. In my code, this works the 1st time, but not again. for i in range(self.QRsize.QRversionList[self.QRversion-1][self.QRspecs[3]]): self.newGeneratorPolynomial = [] self.newGeneratorPolynomial = self.generatorPolynomial for j in range(len(self.newGeneratorPolynomial)): a = int(self.newGeneratorPolynomial[j][2:]) b = self.alpha.decToAlpha[str(self.messagePolynomial[0])] c = self.alpha.alphaToDec[‘a_’ + str((a + b) % 255)] self.newGeneratorPolynomial.pop(j) self.newGeneratorPolynomial.insert(j, c) ~~~more code here before looping back~~~ From my testing, the problem seems to be that the ‘j’ loop modifies ‘self.generatorPolynomial’ and ‘self.newGeneratorPolynomial’ at the same time. What is meant to happen is that ‘self.generatorPolynomial’ is always the same, then ‘self.newGeneratorPolynomial’ copies its data, and that is the one that is modified. Every iteration in the loop should start off by resetting the generator polynomial to what it was, but it isnt doing that. Any help is appreciated! submitted by /u/Dragonmanenderr [link] [comments] 

Sorry in advance for the long explanation.

Background for this code: i am trying to make a QR code generator. Part of the process is to have 2 polynomials, the generator and the message polynomial (represented as lists of alpha notation). I wont go into full depth about how this works, but basically when dividing one polynomial by the other, the first step is to multiply all the terms in the generator polynomial by the first term of the message polynomial. In my code, this works the 1st time, but not again.

for i in range(self.QRsize.QRversionList[self.QRversion-1][self.QRspecs[3]]): self.newGeneratorPolynomial = [] self.newGeneratorPolynomial = self.generatorPolynomial for j in range(len(self.newGeneratorPolynomial)): a = int(self.newGeneratorPolynomial[j][2:]) b = self.alpha.decToAlpha[str(self.messagePolynomial[0])] c = self.alpha.alphaToDec['a_' + str((a + b) % 255)] self.newGeneratorPolynomial.pop(j) self.newGeneratorPolynomial.insert(j, c) ~~~more code here before looping back~~~ 

From my testing, the problem seems to be that the ‘j’ loop modifies ‘self.generatorPolynomial’ and ‘self.newGeneratorPolynomial’ at the same time. What is meant to happen is that ‘self.generatorPolynomial’ is always the same, then ‘self.newGeneratorPolynomial’ copies its data, and that is the one that is modified. Every iteration in the loop should start off by resetting the generator polynomial to what it was, but it isnt doing that.

Any help is appreciated!

submitted by /u/Dragonmanenderr
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *