I am trying to implement an open source desktop application with python. I want to provide both a gui and an API. I know there is no private methods in python but i am trying to find the most elegant way to keep some methods private. I do not want my users to see all list of methods while using API. After some research, I come up with the implementation below and wondering if there is any problem with my implementation of this concept and if there is any room for improvement. Please provide me a review and do not hesitate to ask any questions you have. Here is my try:
from pprint import pprint
# CamelCase because it "acts" like a class
def CounterController():
class CounterControllerPrivate(object):
def __init__(self):
self.counter = 0
def add_one(self):
self.counter += 1
def reset(self):
self.counter = 0
def get_counter(self):
return self.counter
counter_controller = CounterControllerPrivate()
class CounterControllerPublic(object):
def add_one_endpoint(self):
counter_controller.add_one()
return counter_controller.get_counter()
def reset_endpoint(self):
counter_controller.reset()
return counter_controller.get_counter()
return CounterControllerPublic()
# counter attribute is not accessible from out here
controller = CounterController()
print(controller.add_one_endpoint())
print(controller.add_one_endpoint())
print(controller.reset_endpoint())
pprint(dir(controller))
Traceback (most recent call last): File "cr105997.py", line 33, in <module>: controller.add_one_endpoint(): TypeError: add_one_endpoint() missing 1 required positional argument: 'self'
\$\endgroup\$