python - Inheriting from classes unpacked from a list -


say have list of class objects in python (a, b, c) , want inherit of them when building class d, such as:

class a(object):     pass  class b(object):     pass  class c(object):     pass   classes = [a, b, c]  class d(*classes):     pass 

unfortunately syntax error when this. how else can accomplish it, other writing class d(a, b, c)? (there more 3 classes in actual scenario)

you can dynamically create classes using type keyword, in:

>>> classes = [a, b, c] >>> d = type('d', tuple(classes), {}) >>> type(d) <class 'type'> >>> d.__bases__ (<class '__main__.a'>, <class '__main__.b'>, <class '__main__.c'>) 

see 15247075 more examples.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -