Answer the question
In order to leave comments, you need to log in
How to create a global variable in OOP?
There is a dictionary that needs to be created once when starting the program and work with it. I tried to implement this using a global variable, but they say that it is better not to use them in OOP. How can this problem be solved?
class One:
def __init__(self):
Two().keyDir()
class Two:
def keyDir(self):
self.keyboardDir = {}
print(self.keyboardDir)
def message(self):
self.keyboardDir["Word"] = {'Key':'Value'}
print(self.keyboardDir)
Two().message()
if __name__ == "__main__":
One()
Answer the question
In order to leave comments, you need to log in
They are not used due to low security, that is, the lack of encapsulation. Read about the single tone pattern.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question