List-type attributes and name strings
egbert
egbertum at xs4all.nl
Thu Jul 1 06:56:01 EDT 2010
Normally you use setattr() if the name of the attribute is in a
namestring:
>>>> setattr(self, namestring, value)
But my attributes are lists or dictionaries, and I don't seem to be
able to use setattr anymore.
Now I use for a list something like:
>>> self.__dict__[namestring].append(value)
and for a dictionary:
>>> self.__dict__[namestring][keystring]=value
But I have the impression that I am cheating, because users should not
operate on __dict__ directly.
Is that true ? And are there better solutions ?
egbert
--
Egbert Bouwman - Keizersgracht 197 II - 1016 DS Amsterdam - 020 6257991
========================================================================
More information about the Python-list
mailing list