On Sun, 26 Jun 2005 22:42:40 -0400, "Terry Reedy" <[EMAIL PROTECTED]> wrote:
> >"Steve Jorgensen" <[EMAIL PROTECTED]> wrote in message >news:[EMAIL PROTECTED] >> Note how the powerful, context-aware exec() and eval() procedures really >> help >> simplify the code. > >A stylistic note: I believe that most or all of your eval/exec uses could >be done with getattr and setattr instead, which are in the language for >precisely those situations in which the name of an attribute is in a >runtime string. To my mind, this would be simpler and better style. > >> valueExpr = "self.model." + parsed.name >> valueIs = eval(valueExpr) > >I believe this is valueIs = getattr(self.model, parsed.name) > >> methodCall = "self.model." + parsed.name +"(" + parsed.value + ")" >> exec(methodCall) > > >I believe this is getattr(self.model, parsed.name)(parsed.value). > > >> exec("self.model." + parsed.name + "=" + parsed.value) > >I believe this is setattr(self.model, parsed.name, parsed.value). > >and so on. Thanks. I'm new to Python, so I'll take all the style advice I can get. - Steve J. -- http://mail.python.org/mailman/listinfo/python-list