tags:

views:

172

answers:

2
class a(type):
    def __str__(self):
        return 'aaa'
    def __new__(cls, name, bases, attrs):
        attrs['cool']='cool!!!!'
        new_class = super(a,cls).__new__(cls, name, bases, attrs)
                #if 'media' not in attrs:
                    #new_class.media ='media'
        return new_class

class b(object):
    __metaclass__=a
    def __str__(self):
        return 'bbb'

print b
print b()['cool']#how can i print 'cool!!!!'
+1  A: 
print "cool!!!"

Or did I miss something?

I love how SO counts votes: (1 * +1) + (4 * -1) = +2
I got a laugh outta your answer
Erik
+4  A: 
print b().cool

attrs in your __new__ method becomes the object's dictionary. Properties of Python objects are referenced with the . syntax.

jleedev