Jan-10-2019, 02:50 AM
That's rather odd. Getters and setters don't make sense in Python. Since there are no private attributes (such as those in Java), they don't provide any security. Therefore all they can do is slow things down.
I'm not even sure why they are using the term 'private attribute'. If you really need security in Python, as in you need to make sure foo.spam changes every time foo.eggs changes, you use properties.
I do often provide ways for others to not have to access the attributes of the class directly, but I do this to make my classes easier to use. For example, say I have an class that's has a list attribute and some extra tracking attributes. I will override __iter__ so you can just do
What is the name of the book you are using?
I'm not even sure why they are using the term 'private attribute'. If you really need security in Python, as in you need to make sure foo.spam changes every time foo.eggs changes, you use properties.
I do often provide ways for others to not have to access the attributes of the class directly, but I do this to make my classes easier to use. For example, say I have an class that's has a list attribute and some extra tracking attributes. I will override __iter__ so you can just do
for knight in round_table:
rather than for knight in round_table.knights:
.What is the name of the book you are using?
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures