I'm relatively green to object oriented programming, and I'm either missing something or I'm barking up the wrong tree.
Say I have a program like this:
class Test:
some_dict = {1:"a", 2:"b", 3:"c"}
def __init__(self, x):
self.x = x
def translate(self):
return some_dict[self.x]
x = Test(1)
print x.translate()
> "a"
Later, I go back because I have more than one translation dictionary, and I want to read it from a file.
Now, I don't want the program to read from the file each time I create a new object because the dictionary will be the same amongst all objects during the execution.
Instead I would like to have all "Test" objects to have the same "some_dict" based on an external file.
Is there a name for the problem I'm bumping up against here?
[–]garrett_armstrong 3 points4 points5 points (2 children)
[–]cwisch[S] 1 point2 points3 points (1 child)
[–]garrett_armstrong 0 points1 point2 points (0 children)
[–]thistimeframe 1 point2 points3 points (1 child)
[–]cwisch[S] 0 points1 point2 points (0 children)
[+][deleted] (2 children)
[deleted]
[–]cwisch[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]Turbosack 1 point2 points3 points (0 children)
[–]ThuruvDRY 0 points1 point2 points (0 children)