BOOKPYTHON Telegram 3328
Популярный способ объявить абстрактный метод в Python — использовать исключение NotImplementedError:


def human_name(self):
raise NotImplementedError


Хотя этот способ довольно популярен и даже поддерживается IDE (PyCharm считает такой метод абстрактным), у него есть недостаток. Ошибка возникает только при вызове метода, а не при создании экземпляра класса.

Используйте abc, чтобы избежать этой проблемы:


from abc import ABCMeta, abstractmethod
class Service(metaclass=ABCMeta):
@abstractmethod
def human_name(self):
pass


👉@BookPython
👍4



tgoop.com/BookPython/3328
Create:
Last Update:

Популярный способ объявить абстрактный метод в Python — использовать исключение NotImplementedError:


def human_name(self):
raise NotImplementedError


Хотя этот способ довольно популярен и даже поддерживается IDE (PyCharm считает такой метод абстрактным), у него есть недостаток. Ошибка возникает только при вызове метода, а не при создании экземпляра класса.

Используйте abc, чтобы избежать этой проблемы:


from abc import ABCMeta, abstractmethod
class Service(metaclass=ABCMeta):
@abstractmethod
def human_name(self):
pass


👉@BookPython

BY Библиотека Python разработчика | Книги по питону


Share with your friend now:
tgoop.com/BookPython/3328

View MORE
Open in Telegram


Telegram News

Date: |

How to Create a Private or Public Channel on Telegram? A Hong Kong protester with a petrol bomb. File photo: Dylan Hollingsworth/HKFP. Telegram desktop app: In the upper left corner, click the Menu icon (the one with three lines). Select “New Channel” from the drop-down menu. In handing down the sentence yesterday, deputy judge Peter Hui Shiu-keung of the district court said that even if Ng did not post the messages, he cannot shirk responsibility as the owner and administrator of such a big group for allowing these messages that incite illegal behaviors to exist. "Doxxing content is forbidden on Telegram and our moderators routinely remove such content from around the world," said a spokesman for the messaging app, Remi Vaughn.
from us


Telegram Библиотека Python разработчика | Книги по питону
FROM American