consider the following code:
def print_name(*args, **kwargs):
cls = type(*args, **kwargs)
print "hello " + cls.name
return type.__new__( *args, **kwargs)
class B(object):
__metaclass__ = print_name
name = 'animal'
class C(B):
name = "zebra"
class D(B):
name = "pig"
What i'm trying to achieve is have the function print_name be called on B sub classes(C and D) and make it print the static attribute name. So the desired output should look like this -
animal
zebra
pig
Thank you very much!