Le Mon, 16 Feb 2009 12:01:24 -0800,
Marc Tompkins <marc.tompk...@gmail.com> a écrit :

> On Mon, Feb 16, 2009 at 11:58 AM, Wayne Watson <sierra_mtnv...@sbcglobal.net
> > wrote:
> 
> >  Python doesn't like the code in the Subject (unqualified exec not allowed
> > in function). but easily likes self.abc="22". However, I'd like to assemble
> > the assignment as a string, as shown in Subject, and execute it. Is there a
> > way to do this?
> > --
> >
> > varName = "abc"
> varValue = 22
> setattr(self, varName, varValue)


>>> exec("name='22'")
>>> name
'22'
>>> exec("name=\"22\"")
>>> name
'22'


------
la vida e estranya
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to