I have this really simple scenario where I want to use one function in multiple classes. So I declare it before the class and then I try to use.
def __ext_function(x):
print(f'Test{x}')
class MyClass():
some_value: int
def __init__(self, some_value):
self.some_value = some_value
__ext_function(1)
a = MyClass(some_value=1)
But for some reason it keeps telling me that it does not exit:
NameError: name '_MyClass__ext_function' is not defined
I have seen other questions with solutions like this:
def __ext_function(x):
print(f'Test {x}')
class MyClass():
some_value: int
ext_func = staticmethod(__ext_function)
def __init__(self, some_value):
self.some_value = some_value
self.ext_func(1)
a = MyClass(some_value=1)
But none seems to work.