PYHINTS Telegram 12
Python Hints
این کد که احتمالاً بسیار هم می‌بینید و استفاده می‌کنید ۲ تا باگ داره، که ۱ مورد می‌تونه حتی شمارو توی مصاحبه رد کنه می‌تونید باگ‌هارو پیدا کنید ؟ @PyHints
ولی باگ دوم که من حتی توی سورس کد فریمورک‌ها و کتابخانه‌های معروف پایتون هم زیاد دیدم به راحتی میتونه توی مصاحبه‌های اولیه اوضاع رو بر علیه شما بکنه

مشکل باز هم توی این خط هست :

return f"Person(name={self.name!r}, age={self.age!r})"

اگر دقت کنید اسم کلاس hard code شده ینی اگر بعد از مدتی که پروژه بزرگ شد بجای کلاس Person از مثلا Student استفاده بشه و فراموش کنید که
__repr__
رو تغییر بدید؛ بوقت دیباگ کردن کد باعث سردرگمی بزرگی میشه؛
راه حل :
return f"{type(self).__name__}(name={self.name!r}, age={self.age!r})"
که خب
type(self)
میگه که ی instance از کلاس Person هست و وقتی __name__ رو میگیرم دقیقا اسم کلاس رو برمیگردونه ینی Person هر تغییری هم که روی اسم کلاس اعمال بشه هیچ نیازی به تغییر
__repr__
نیست.

توی تصویر این پست هم می‌تونید ببینید :
https://www.tgoop.com/pyHints/7


@PyHints
👍76❤‍🔥6👌321👎1🆒1



tgoop.com/pyHints/12
Create:
Last Update:

ولی باگ دوم که من حتی توی سورس کد فریمورک‌ها و کتابخانه‌های معروف پایتون هم زیاد دیدم به راحتی میتونه توی مصاحبه‌های اولیه اوضاع رو بر علیه شما بکنه

مشکل باز هم توی این خط هست :

return f"Person(name={self.name!r}, age={self.age!r})"

اگر دقت کنید اسم کلاس hard code شده ینی اگر بعد از مدتی که پروژه بزرگ شد بجای کلاس Person از مثلا Student استفاده بشه و فراموش کنید که
__repr__
رو تغییر بدید؛ بوقت دیباگ کردن کد باعث سردرگمی بزرگی میشه؛
راه حل :
return f"{type(self).__name__}(name={self.name!r}, age={self.age!r})"
که خب
type(self)
میگه که ی instance از کلاس Person هست و وقتی __name__ رو میگیرم دقیقا اسم کلاس رو برمیگردونه ینی Person هر تغییری هم که روی اسم کلاس اعمال بشه هیچ نیازی به تغییر

__repr__
نیست.

توی تصویر این پست هم می‌تونید ببینید :
https://www.tgoop.com/pyHints/7


@PyHints

BY Python Hints




Share with your friend now:
tgoop.com/pyHints/12

View MORE
Open in Telegram


Telegram News

Date: |

Ng, who had pleaded not guilty to all charges, had been detained for more than 20 months. His channel was said to have contained around 120 messages and photos that incited others to vandalise pro-government shops and commit criminal damage targeting police stations. Content is editable within two days of publishing Deputy District Judge Peter Hui sentenced computer technician Ng Man-ho on Thursday, a month after the 27-year-old, who ran a Telegram group called SUCK Channel, was found guilty of seven charges of conspiring to incite others to commit illegal acts during the 2019 extradition bill protests and subsequent months. During a meeting with the president of the Supreme Electoral Court (TSE) on June 6, Telegram's Vice President Ilya Perekopsky announced the initiatives. According to the executive, Brazil is the first country in the world where Telegram is introducing the features, which could be expanded to other countries facing threats to democracy through the dissemination of false content. A few years ago, you had to use a special bot to run a poll on Telegram. Now you can easily do that yourself in two clicks. Hit the Menu icon and select “Create Poll.” Write your question and add up to 10 options. Running polls is a powerful strategy for getting feedback from your audience. If you’re considering the possibility of modifying your channel in any way, be sure to ask your subscribers’ opinions first.
from us


Telegram Python Hints
FROM American