Python: calling a private method within static method

27 Views Asked by At

What is the correct way and best practice to call a private method from within a static method in python 3.x? See example below:

class Class_A:
    def __init__(self, some_attribute):
        self.some_attr = some_attribute

    def __private_method(arg_a):
        print(arg)
    
    @staticmethod
    def some_static_method(arg_a):
        __private_method(arg_a) # "__private_method" is not defined

Now, if I instantiate a Class_A object and call the static method:

my_instance = Class_A("John Doe")
my_instance.some_static_method("Not his real name")

I get a NameError: NameError: name '__private_method' is not defined

0

There are 0 best solutions below