Adam, remember that in Python, when you say:
a = read_dict_from_file() b = a
... you are not actually copying a and thus, using more memory, you just make b another reference to the same object.
Thus, basically, any of the solutions you propose will be much better in terms of memory usage. Basically, read the dictionary once , and then hold onto the link to it. Regardless of whether you are doing this with a global variable or passing it to each instance or something else, you will reference the same object and not duplicate it.
Which one is the most pythons? This is a whole "black worm of worms", but here is what I would do personally:
def main(args): run_initialization_stuff() dictionary = read_dictionary_from_file() solvers = [ Solver(class=x, dictionary=dictionary) for x in len(number_of_solvers) ]
NTN.
source share