Missing Something Simple
harold.fellermann at upf.edu
Tue Jul 12 16:13:44 CEST 2005
> I have a list of variables, which I am iterating over. I need to set
> the value of each variable. My code looks like:
> varList = [ varOne, varTwo, varThree, varFour ]
> for indivVar in varList:
> indivVar = returnVarFromFunction()
> However, none of the variables in the list are being set.
You only change the value of the local variable in the body
of the for loop. it has no effect on the list. you could do e.g.
varList = [vorOne,varTwo,varThree,varFour]
for i in len(varList) :
varList[i] = returnVarFromFunction()
However, as in this example the former list values are not used anyway,
you could just write:
varList = [ returnVarFromFunction for i varList ]
- harold -
Tages Arbeit, abends Gäste,
saure Wochen, frohe Feste!
-- Johann Wolfgang v. Goethe
More information about the Python-list