Pythonで作成したboggle-clone用のネットワークサーバーを作成しています。これは、ユーザーを受け入れ、ボードを解決し、プレーヤーの入力をスコアリングします。私が使用している辞書ファイルは1.8MB(ENABLE2K辞書)であり、いくつかのゲームソルバークラスで使用できるようにする必要があります。現在、各クラスがファイルを1行ずつ繰り返し、ハッシュテーブル(連想配列)を生成するようにしていますが、インスタンス化するソルバークラスが多いほど、より多くのメモリを消費します。
What I would like to do is import the dictionary file once and pass it to each solver instance as they need it. But what is the best way to do this? Should I import the dictionary in the global space, then access it in the solver class as globals()['dictionary']? Or should I import the dictionary then pass it as an argument to the class constructor? Is one of these better than the other? Is there a third option?