Re: syntax error in eval()

2005-01-10 Thread harold fellermann
Thank you, Duncan and Steven. I completely forgot about setattr. Of course that's the way ... as its name might suggest *g* What you are doing wrong is attempting to use eval before exhausting all the simpler techniques. Why not just call 'setattr'? setattr(X, 'attr', 5) BTW, the syntax error is

Re: syntax error in eval()

2005-01-10 Thread Duncan Booth
harold fellermann wrote: > Python 2.4 (#1, Dec 30 2004, 08:00:10) > [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> class X : pass > ... > >>> attrname = "attr" > >>> eval("X.%s = val" % attrname , {"X":X

Re: syntax error in eval()

2005-01-10 Thread Steven Bethard
harold fellermann wrote: Python 2.4 (#1, Dec 30 2004, 08:00:10) [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> class X : pass ... >>> attrname = "attr" >>> eval("X.%s = val" % attrname , {"X":X, "val":5})