Can a static member be private in a python class? What is the best practice for calling a getter? If not, is it a bad practice and why?
Asked
Active
Viewed 43 times
-1
-
1Depends what you mean by "private". Nothing is really private. – khelwood May 16 '19 at 07:45
-
1I think it would help if you showed some code demonstrating what you're asking. Otherwise, the question is to ambiguous for folks to help. If you haven't seen it, [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) is a good resource on how to formulate your question, and [What topics can I ask about here?](https://stackoverflow.com/help/on-topic) outlines the acceptable topics for Stack Overflow. – John Szakmeister May 16 '19 at 08:38
1 Answers
0
In python, nothing really is private.
Best practice for anything considered private, is to prefix the member with an underscore; see What is the meaning of a single and a double underscore before an object name?
If you like a getter / setter based approach, check out the python property decorator. However, in my experience, you would typically just have those public members be public (not prefixed with underscore). The typical use case I would use a property for is some calculated attribute (i.e. a method call disguised as an attribute).

martyn
- 676
- 7
- 17
-
thanks, i understand about underscore prefix and the property decorator, and understand the private notation with underscore. h/e I couldn't write a property decoration for a *static* class member. I would like to get the benefits of the property decoration , on a static member of the class. – aviyaChe May 16 '19 at 08:47