In Python, which is the best way (style) to allow public access to object variables?
There are many options that I saw in different languages, I was wondering which one (if any) is the preferred Python method? These are the options that I am currently tearing between:
- Allow direct access to object variables (e.g. print (object.variable)), ignore data hiding
- Allow access to object variables using the 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, what do you call methods? (get_variablename () or just variablename, etc.?)
What does everyone recommend for this?
thank!
Lucy
source
share