1

There are situations when I need to set class attributes from within an instance. One solution would be to create a class method that is called the instance method. That class method would be used to set the class attribute.

However, I would like to know if there is a way to define a property and its setter to edit a class attribute from within an instance method. In other words, I would like to have a class attribute that could be set from any instance while still remaining shared across instances.

Specifically, this is my use case: my instance needs to be destroyed and recreated. However, upon recreation, I need to access a class attribute that stores the reason why the previous instance has been destroyed to initialize the object properly.

Thank you

user1315621
  • 3,044
  • 9
  • 42
  • 86
  • 1
    "my instance needs to be destroyed and recreated." You say this like you're trying to implement a Singleton. Why do you need an instance at all? What happens when it's destroyed and recreated? Could you just simulate that with other classmethods, and use class attributes in place of instance methods? – Karl Knechtel Mar 23 '21 at 22:32
  • You can always create your own descriptor – juanpa.arrivillaga Mar 23 '21 at 22:41

0 Answers0