inherit dynamically from multiple class


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. class Slave1(object):
  2. t1="1"
  3. class Slave2(object):
  4. t2="2"
  5.  
  6. class MetaClass(type):
  7. def __new__(meta, classname, bases, classDict):
  8. bases = tuple([Slave1, Slave2])
  9. return type.__new__(meta, classname, bases, classDict)
  10.  
  11. class Master(object):
  12. __metaclass__ = MetaClass
  13.  
  14. m=Master()
  15. print m.t1
  16. print m.t2

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.