getattr/setattr q.

Paulo da Silva psdasilvaX at esotericaX.ptX
Tue Apr 3 15:32:41 EDT 2007


> Yes, but you shouldn't unless you really need to. You're better off
> rethinking your algorithm.


I need it but inside a class. The idea is to pass an instance of a class
 (think of something like a record but with some methods inside) with
"fields", whose names are not known in advance, to another class that
must handle those "fields" at the caller request given their names as
parameter strings.

Another use I am thinking of is in a xml driven program where some
parameters "foo=bar", read as strings, must be converted into internal
variables xxx_foo=bar. I have written a 1st draft using dicts but this
way it is much easier and readable.


Regards
Paulo



More information about the Python-list mailing list