Рубрика «__class__»

Короткая заметка из серии «Вас предупреждали».

Переход с классических языков программирования на Питон доставляет немало сюрпризов.
Читаем документацию:

Generally speaking, instance variables are for data unique to each instance and class variables are for attributes and methods shared by all instances of the class

Попробуем поиграться

class Vessel:
    #class attribute
    vtype = "boat"

    #instance attribute
    def __init__(self, name):
        self.name = name

    # ислючительно для печати
    def __str__(self):
        res= '>>'
        for a in inspect.getmembers( self):
            if not a[0].startswith("__"): res += f"{a[0]}={a[1]:<14}"
        for a in inspect.getmembers( self.__class__):
            if not a[0].startswith("__"): res += f"__class__.{a[0]}={a[1]:<14}"

        return res

Читать полностью »


https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js