Aug-20-2018, 05:56 PM
To answer your bottom questions:
Setters and getters are not generally used in Python (read: extremely discouraged).
Unless a setter or getter would do actual work you would never write one, and if you were in a situation where you needed to write one, you would use
Privacy: again same here. Python is not Java. Python has a much more "we are all adults here" attitude towards data access. We do not use private/public/protected data. You write a class and make it clear how the API operates but if someone wants to touch the mechanics underneath you don't generally try to stop them. Single underscore variables have their place but they are not common; don't get in the habit of trying to mark all your class members "private". It just doesn't work that way.
And absolutely don't mark variables with leading double underscores. This causes name mangling, again doesn't actually enforce privacy, and most importantly annoys the hell out of other Python programmers.
Setters and getters are not generally used in Python (read: extremely discouraged).
Unless a setter or getter would do actual work you would never write one, and if you were in a situation where you needed to write one, you would use
@property
decorators and such.Privacy: again same here. Python is not Java. Python has a much more "we are all adults here" attitude towards data access. We do not use private/public/protected data. You write a class and make it clear how the API operates but if someone wants to touch the mechanics underneath you don't generally try to stop them. Single underscore variables have their place but they are not common; don't get in the habit of trying to mark all your class members "private". It just doesn't work that way.
And absolutely don't mark variables with leading double underscores. This causes name mangling, again doesn't actually enforce privacy, and most importantly annoys the hell out of other Python programmers.