[Tutor] exec "self.abc=22" ?

Marc Tompkins marc.tompkins at gmail.com
Mon Feb 16 21:01:24 CET 2009


On Mon, Feb 16, 2009 at 11:58 AM, Wayne Watson <sierra_mtnview at 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)


-- 
www.fsrtechnologies.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090216/05e618a8/attachment.htm>


More information about the Tutor mailing list