Dynamically creating properties?

Andy Dingley dingbat at codesmiths.com
Thu Oct 27 15:59:57 EDT 2011


I have some XML, with a variable and somewhat unknown structure. I'd
like to encapsulate this in a Python class and expose the text of the
elements within as properties.

How can I dynamically generate properties (or methods) and add them to
my class?  I can easily produce a dictionary of the required element
names and their text values, but how do I create new properties at run
time?

Thanks,



More information about the Python-list mailing list