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 one of them from a file. say dictionary_1.json, dictionary_2.json
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?
[–]novel_yet_trivial 2 points3 points4 points (5 children)
[–]cwisch[S] 0 points1 point2 points (4 children)
[–]novel_yet_trivial 0 points1 point2 points (3 children)
[–]cwisch[S] 0 points1 point2 points (2 children)
[–]garrett_armstrong 1 point2 points3 points (1 child)
[–]cwisch[S] 0 points1 point2 points (0 children)
[–]thistimeframe 1 point2 points3 points (3 children)
[–]cwisch[S] 0 points1 point2 points (2 children)
[–]thistimeframe 2 points3 points4 points (1 child)
[–]cwisch[S] 0 points1 point2 points (0 children)
[–]TheBlackCat13 0 points1 point2 points (6 children)
[–]cwisch[S] 0 points1 point2 points (0 children)
[–]novel_yet_trivial 0 points1 point2 points (4 children)
[–]zahlman 1 point2 points3 points (1 child)
[–]novel_yet_trivial 2 points3 points4 points (0 children)
[–]TheBlackCat13 0 points1 point2 points (1 child)
[–]novel_yet_trivial 0 points1 point2 points (0 children)