for example i have myClassFile.py file with code as follow:
class myClass:
def first(self):
return 'tea'
def second(self):
print(f'drink {self.first()}')
then i have run.py file with code as follow:
from myClassFile import myClass
class_ = myClass()
class_.second()
which when i run will output
>>> 'drink tea'
how to prevent someone to write below code on run.py file or outside myClass ?
class_.first()
so that if they used that method outside myClass class it will be an error or some sort
_firstto indicate that it's not part of the public interface, but there's really nothing you can do to enforce that decision.