[Tutor] creating a dict-like class - asigning variables... this one may take some thought ; )

Kent Johnson kent37 at tds.net
Thu May 28 16:52:57 CEST 2009


On Thu, May 28, 2009 at 6:47 AM, John [H2O] <washakie at gmail.com> wrote:

> # Now I want to put them into my stuff class:
>    for j in range(len(a)):
>        cmd = "h.%s = a[%s][0]" % (I[j],j)
>        eval(cmd)

Use setattr() rather than eval. Something like
  setattr(h, l[j], a[j][0])

Kent


More information about the Tutor mailing list