variable hell

Steve Holden steve at holdenweb.com
Thu Aug 25 16:29:11 EDT 2005


rafi wrote:
> Reinhold Birkenfeld wrote:
> 
> 
>>>> exec(eval("'a%s=%s' % (count, value)"))
>>>
>>>why using the eval?
>>>
>>>exec ('a%s=%s' % (count, value))
>>>
>>>should be fine
>>
>>And this demonstrates why exec as a statement was a mistake ;)
>>
>>It actually is
>>
>>exec 'a%s=%s' % (count, value)
> 
> 
> Noted.
> 
> In the meantime another question I cannot find an answer to: any idea 
> why does eval() consider '=' as a syntax error?
> 
>  >>> eval ('a=1')
> Traceback (most recent call last):
>    File "<stdin>", line 1, in ?
>    File "<string>", line 1
>      a=1
>       ^
> SyntaxError: invalid syntax
> 
> Thanks
> 
Because eval() takes an expression as an argument, and assignment is a 
statement.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC             http://www.holdenweb.com/




More information about the Python-list mailing list