variable hell

Robert Kern rkern at ucsd.edu
Mon Aug 29 05:13:17 EDT 2005


Adriaan Renting wrote:

> My original code was: exec(eval("'a%s=%s' % (count, value)"))
> Then Rafi said: exec("'a%s=%s' % (count, value)")
> To which I responded that his example does not work in my Python, and I think it's invalid.
> Then Martin came with: exec 'a%s = %s' % (count, value)
> This does work.
> But he seems to keep telling me I'm quoting him wrong, while I'm quoting Rafi.

Read more carefully. rafi did not put in the extraneous quotes.

rafi:
>>Adriaan Renting wrote: 
>>
>>>You might be able to do something along the lines of 
>>>
>>>for count in range(0,maxcount): 
>>>value = values[count] 
>>>exec(eval("'a%s=%s' % (count, value)")) 
>>
>>why using the eval? 
>> 
>>exec ('a%s=%s' % (count, value)) 
>> 
>>should be fine 
>> 
>>-- 
>>rafi 

See? No extra quotes.

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter




More information about the Python-list mailing list