python 2.2 question...

Martin von Loewis loewis at informatik.hu-berlin.de
Tue Sep 25 11:50:21 EDT 2001


"Paolo Invernizzi" <paoloinvernizzi at dmsware.com> writes:

> And here we are again at the second part of my original post...
> The problem with metaclasses is that I cannot specify in the "special"
> string anything related to the original class object...
> The return value is "always" <special>, and I see no way to turn it in
> something like <special class c id <0xAddress>>

But it's easy:

class t(type):
  def __repr__(self):
      return '<special class %s at %x>' % (self.__name__,id(self))

class c(object):
  __metaclass__=t

print `c`

gives

<special class c at f7e88>

Notice how the self argument of the metatype's method is the class
object.

Regards,
Martin



More information about the Python-list mailing list