Puzzle: anonymous tuple unpacking w/o eval
Paul Rubin
http
Fri May 16 17:38:15 EDT 2003
"Edward K. Ream" <edreamleo at charter.net> writes:
> Eval can be used sometimes:
>
> aList = (("a",val1),("b",val2),("c",val3))
> ...
> for name,val in aList:
> eval("%s=%s" % (name,str(val)))
>
> This only works for string and numeric values where str(val)==repr(val),
> sort of.
>
> Anyway, is there any way to get the same effect without using eval? setattr
> might be useful, and I haven't figured out how.
Why would you want to do that? Certainly not for security reasons,
since it's every bit as dangerous as using eval.
More information about the Python-list
mailing list