Hello tutorians,

Am I missing something or don't classes know how they're called (unlike funcs, which have a __name__ attribute, very practicle)? Is there a way to get it otherwise?

The point is to have a super-type define a general __repr__ like eg:

class SuperType:
    # ...
    def __repr__ (sef):
        return "%s(stuff)" % (self.__class__.__name__, stuff)

But I need each class to know its name. Subtypes are actually defined by users (of a lib), presently they are forced to write the name explicitely, which is stupid since they already give it as var name:

class SubType (SuperType):
    __name__ = "SubType"
    # ....

Denis
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to