tgoop.com/pyHints/319
Create:
Last Update:
Last Update:
من راجب repr
, str
, ... صحبت کردم.
این کد رو یکی از اعضا فرستاده (درحال code review این کد رو دیده)
@dataclassی مورد رو من بگم و بعد سکوت کنم :
class CasbinRuleEntity:
id: typing.Optional[int] = None
ptype: typing.Optional[str] = None
v0: typing.Optional[str] = None
v1: typing.Optional[str] = None
v2: typing.Optional[str] = None
v3: typing.Optional[str] = None
v4: typing.Optional[str] = None
v5: typing.Optional[str] = None
def __str__(self):
arr = [self.ptype]
for v in (self.v0, self.v1, self.v2, self.v3, self.v4, self.v5):
if v is None:
break
arr.append(v)
return ', '.join(arr)
def __repr__(self):
return '<CasbinRule {}: "{}">'.format(self.id, str(self))
یکی از دلایلی که
@dataclass
رو استفاده میکنیم این هست که دیگه
repr
بدرد نخور ننویسیم.باقی مشکلات رو شما بگید (به اکثر موارد قبلاً اشاره شده توی کانال)
BY Python Hints
Share with your friend now:
tgoop.com/pyHints/319