PYHINTS Telegram 319
من راجب 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 بدرد نخور ننویسیم.

باقی مشکلات رو شما بگید (به اکثر موارد قبلاً اشاره شده توی کانال)
🤔14👍92🍓21👎1🔥1😱1🆒1



tgoop.com/pyHints/319
Create:
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

View MORE
Open in Telegram


Telegram News

Date: |

The visual aspect of channels is very critical. In fact, design is the first thing that a potential subscriber pays attention to, even though unconsciously. Administrators The main design elements of your Telegram channel include a name, bio (brief description), and avatar. Your bio should be: Add the logo from your device. Adjust the visible area of your image. Congratulations! Now your Telegram channel has a face Click “Save”.! According to media reports, the privacy watchdog was considering “blacklisting” some online platforms that have repeatedly posted doxxing information, with sources saying most messages were shared on Telegram.
from us


Telegram Python Hints
FROM American