私はいくつかの人に尋ねました。私のコードは同じですが、私はゲームのタイトルをインポートしようとしています。この関数はソースファイル内で動作しますが、別のファイルにインポートした後では機能しません。ここでは、ファイルやCMDで生じる誤差は次のとおりです。インポートされた関数を呼び出すエラー:名前が定義されていません
Game.py:
from Events import *
from Character import *
Opening()
Character.py:
from Events import *
from Game import *
Events.py:
from Game import *
from Character import *
def Opening():
print " _____ _ _____ _____ _ _ "
print "/ ___| | | /___| /__ \ | | (_) "
print "\ `--. _ _| |__ ______\ `--. _ __ __ _ ___ ___ |/\/ __ _ ___ ___ _ __ | |__ ___ _ __ _ __ _ "
print " `--. \ | | | '_ \______|`--. \ '_ \/_` |/ __/ _ \ | | /_` |/ __/ _ \| '_ \| '_ \/_ \| '__| |/ _` |"
print "/\__//|_| | |_) | /\__//|_) | (_| | (_| __/ | \__/\ (_| | (_| (_) | |_) | | | | (_) | | | | (_| |"
print "\____/ \__,_|_.__/ \____/| .__/ \__,_|\___\___| \____/\__,_|\___\___/| .__/|_| |_|\___/|_| |_|\__,_|"
print " | | | | "
print " |_| |_| "
が、後cmd.pyでGame.pyファイルを実行すると、エラーが発生します:
Traceback (most recent call last): File "Game.py", line 2, in <module> from Events import * File "/tmp/so/Events.py", line 2, in <module> from Game import * File "/tmp/so/Game.py", line 8, in <module> Opening() NameError: name 'Opening' is not defined
なぜ 'イベント'は 'ゲーム'をインポートしますか?また、[PEP-8](https://www.python.org/dev/peps/pep-0008/)を読むことをお勧めします。 – jonrsharpe
'import events'を試してください。' Events.Opening() ' –