I am having an unexpected issue in some code, and could reproduce it in a more simple example:
file1.py
class FirstClass: def function1(self): print("hello from function1") def __function2(self): print("hello from function2") file2.py
from file1 import FirstClass fc = FirstClass() fc.function1() fc.__function2() ..and here's what happens:
$ python file2.py hello from function1 Traceback (most recent call last): File "file2.py", line 7, in <module> fc.__function2() AttributeError: FirstClass instance has no attribute '__function2' What can you do so that the call to __function2 works? I am not really supposed to go into that imported class and make that private method public.
_FirstClass__function2. If you must. I won't bother with the health warnings. See the section Private Variables here: docs.python.org/3.7/tutorial/classes.htmldef __somefunctionis not a private method, it's used for avoiding namespace collisions, as python has no privacy model for access