I have a question regarding python metaclasses.

Lets say i wanted to create a metaclass that i call Tree. This metaclass
creates in an object __parent__ and __children__. these variables are set by
the __setattr__ and __delattr__. Essentially it will check if the variable
type inherits from the root object that inherits from the metaclass. @[EMAIL 
PROTECTED] So
a psuedo example is as follows:

class Tree(type):
 def __setattr__(self, varname, varval):
   #do stuff
  pass

 def __delattr__(self, varname):
   #do other stuff
  pass

class Power(Tree):
 """This is a root object"""
 def __init__(self):
   self.power = 0

 def getPower(self):
   return self.power

 def changePower(self, power):
   self.power += power
   if self.__parent__ != None:
     self.__parent__.changePower(power)


so in this example, any object that inherits from Power will automatically
update the parental power value, essentially the power values trickle up.
So that is one trick im trying to do, just wondering if there are any
caveats or resources i should know about.

The other thing i really have little clue how to do. Lets say i have an
object:

class SuperList(list):
 pass

foo = SuperList
foo.append(somobject)

now lets say i want SuperList to pass any calls that are made onto it, to
all of its children. So by saying foo.someFunc(), it will in turn do:
for item in self:
 item.someFunc()

however, i want the function to be arbitrary. I've read comment on the apply
function, but how does this apply to objects? And is it possible to
intercept function calls on an object?

--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list

Reply via email to