variable hell

Ron Garret rNOSPAMon at flownet.com
Thu Aug 25 19:25:38 EDT 2005


In article <mailman.3535.1125002125.10512.python-list at python.org>,
 Steve Holden <steve at holdenweb.com> wrote:

> 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.

And if you find this distinction annoying, try Lisp.

rg



More information about the Python-list mailing list