現在、PyGame を使用して複数ファイルの Python (2.6.5) ゲームを作成しようとしています。問題は、ファイルの 1 つ「pyconsole.py」が、プライマリ ファイル「main.py」によってインポートされた他のオブジェクトのインスタンスでメソッドを呼び出せる必要があることです。問題は、すべてのゲーム オブジェクト (プレイヤーの船、敵の船、ステーションなど) のインスタンスを保持するためのリストがメイン ファイルにあることですが、そのリストからメソッドを呼び出すことができないようです。from pyconsole import *メインループが開始する前に「main.py」で実行しているにもかかわらず、 「pyconsole.py」。これは単に不可能であり、代わりに M4 を使用してすべてのファイルを 1 つのファイルに結合し、それをバイトコードでコンパイルしてテスト/配布する必要がありますか?
例:
bash$ cat test.py
#!/usr/bin/python
import math, distancefrom00
foo = 5
class BarClass:
    def __init__(self):
        self.baz = 10
    def get(self):
        print "The BAZ is ", self.baz
    def switch(self)
        self.baz = 15
        self.get()
bar = BarClass()
def main():
    bar.switch()
    print distancefrom00.calculate([2, 4])
if __name__ == '__main__': main()
bash$ cat distancefrom00.py
#!/usr/bin/python
import math
import test
def calculate(otherpoint):
    return str(math.hypot(otherpoint[0], otherpoint[1]))+" (foo = "+str(test.foo)+"; "+test.bar.get()+")"
bash$ python test.py
The BAZ is  15
The BAZ is  10
Traceback (most recent call last):
  File "test.py", line 24, in <module>
    if __name__ == '__main__': main()
  File "test.py", line 22, in main
    print distancefrom00.calculate([2, 4])
  File "/home/archie/Development/Python/Import Test/distancefrom00.py", line 8, in calculate
    return str(math.hypot(otherpoint[0], otherpoint[1]))+" (foo = "+str(test.foo)+"; "+test.bar.get()+")"
TypeError: cannot concatenate 'str' and 'NoneType' objects
ここで、Python の名前、クラス、およびそのすべてについてのある程度限定された理解が正しい場合、NoneType は、その名前test.bar.get()、つまり、test.bar何にも割り当てられていないことを意味します。