我有两个文件。一个名为“variables.py”的函数在:
def get_players():
'''
(NoneType) -> Dictionary
Asks for player names
'''
loop = True
players = {}
while loop == True:
player = input("Enter player names: ")
player = player.strip()
if player in players or player == "":
print("Choose a different name!")
elif "player1" in players:
players["player2"] = [player, 0]
elif player not in players:
players["player1"] = [player, 0]
if len(players) >= 2:
loop = False
return players
同一目录中的另一个文件名为“game.py”,其中包含:
import variables
players = get_players()
当我尝试运行“game.py”时,NameError: name 'get_players' is not defined
为什么会出现此错误?!我已经尝试了一切!