+ 1
Reassigning Instance Attributes (Python OOP)
Hello guys, I have a question regarding python OOP. Is it a good practice to change instance/object attributes from code outside of the class? like what I did in this example code. If it's not, then what should we do to change object attributes that have been instantiated? Thank you https://code.sololearn.com/cx8DJdfC2LLe/?ref=app
4 Answers
+ 2
Thats great! You could also make a color_change method that can change the color to any you type in.
Thats a special cat you have there
+ 1
In Python, and as far as I know, changing properties that way is acceptable, though I'm unsure if it's pythonic.
I remember you can define getters and setters using decorators.
I refer you to this article for more information: https://medium.com/@pranaygore/setters-and-getters-in-python-76b5473b3c83
Regards! :D