reflection - Trying to dynaimcally create properties at runtime with Python using reflected data -


so i'm trying figure out if want possible. writing test code application, , have objects contain properties representing of elements have in interface our product. want able pass in applciation runner , data object new class , have dynamically generate set of accessor properties based upon subset of properties in data object. idea far:

  1. create subclass of property includes metadata required extracting information interface
  2. refactor existing data objects use new property subclass relevant fields in ui
  3. create new generator class accepts ui driver object , data object
    • reflects data object list of members of of new property subclass type
    • stores information ui based upon metdadata in property subclass members of generator class instance (planning on using setattr)
    • create properties @ run time make members created in (b) read-only , provide interface consistant existing code (ie using .[name] instead of .[name]())

i think have figured out except step 3c. there way create properties dynamically @ runtime? appreciated.

not sure that's want. define dynamic read-only property getattr , setattr method. here example:

class x(object):     data = {'x' : 123, 'y' : 456}     def __getattr__(self, name):         if name in self.data:             return self.data[name]         raise attributeerror(name)      def __setattr__(self, name, value):         if name in self.data:             return none         return super(x, self).__setattr__(name, value)  = x() print a.x, a.y a.x = 0 print a.x 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -