Answer the question
In order to leave comments, you need to log in
How to make a python pattern?
Help me create a singleton pattern or decorator in this code please. How best to write it and what to 'attach' to?
class Pet:
def __init__(self, name, colour):
self.__name = name
self.__colour = colour
@property
def colour(self):
return self.__colour
@colour.setter
def colour(self, colour):
if colour == 'grey':
self.__colour = colour
else:
print("Такого кота не існує")
@property
def name(self):
return self.__name
def display_info(self):
print("Ім’я:", self.__name, "Колір:", self.__colour)
marsik = Pet("Marsik", "grey")
marsik.colour = "blue"
marsik.colour = "grey"
marsik.display_info()
#Декоратори
def feeding(fn):
def feed():
print("Годувати кота")
fn()
print("Перестати годувати кота")
return feed
@feeding
def feed_cat():
print("Годую кота")
print(feed_cat())
Answer the question
In order to leave comments, you need to log in
Here is an example of how to make such a decorator pattern with your code, I advise you to figure it out yourself
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question