[CentralOH] Dynamic Access to Class Properties

Mark Erbaugh mark at microenh.com
Wed Jun 18 03:24:34 CEST 2008


I suspect I've gone about this all wrong, but anyways...

I have developed a class that encapsulates access to a moderately
complex database object.  Once data has been retrieved from the database
the various fields are accessed using properties.  There are about 70
such properties. Once the fields have been manipulated, the data can be
written back to the database using a class method.

On the GUI end, I developed a GUI where each user edit field knows the
name of the property which contains the field it represents. A method of
the form containing the user edit fields can tell all of the edit fields
to load the data from or to save the data to the data instance.

For example the facility name is accessed as the property facility_name.
The edit field for facility name has a string data member with the value
'facility_name'.

Is there a way, other than exec'ing some code to convert the string
'facility_name' into the data instance property facility_name?

Another thought.  Would it be possible for the edit field to store the
actual property, rather than the value it contains?  For example, say
the edit field has a data member called prop.  Is there a way that I
could make it so when the data member could do value = prop to retrieve
and prop = value to set the property value? Is this currying?  FWIW, I'm
using Python 2.4, I know there were some changes regarding this in
Python 2.5.



More information about the CentralOH mailing list