In Python, which is the best way (style wise) to allow public access to an object's variables?
There are lots of options I've seen from different languages, I was wondering which of these (if any) is the preferred Python method? These are the options I'm currently torn between:
- Allow direct access to object variables (e.g. print(object.variable)), ignore data hiding
- Allow access to object variables by a wrapper function:
class X:
variable_a = 0
variable_b = 0
...
def get_variable_a(self):
return self.variable_a
If this is the recommended way, how do you name the methods? (get_variablename(), or just variablename etc?)
What does everyone recommend for this?
thanks!
Lucy