Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
PythonとPygameを使用して、作業中のゲームのメイン スクリプトとは別のスクリプトで変数を作成する必要があります。
例えば:
def test(): a = 10 def testing(): return a
次に、次のようなコードを実行します。
import (script name) script name.test() script name.testing()
そして、この後、エラーが発生します。この問題を解決するにはどうすればよいですか?
testing() の 'a' はグローバル変数ではないため、前の関数 test() からは認識されません。本当に test() から 'a' を使用したい場合は、おそらく 'a' をグローバル変数として定義できます。