Метаморфозы атрибутов класса |
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://habr.com/post/427065/?utm_source=habrahabr&utm_medium=rss&utm_campaign=427065
Комментировать | « Пред. запись — К дневнику — След. запись » | Страницы: [1] [Новые] |