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

Kent Johnson kent37 at tds.net
Tue Feb 17 12:35:35 CET 2009


On Mon, Feb 16, 2009 at 4:01 PM, Wayne Watson
<sierra_mtnview at sbcglobal.net> wrote:

> I see Marc covered it with setattr. How does one do it with a dictionary?

Instead of trying to create variables with variable names, use the
names as keys in a dict. So instead of
  exec "self.abc=22"
you might use
  self.values = {}
  self.values['abc'] = 22

Kent


More information about the Tutor mailing list