我不知道如何去這個...調用其它的腳本和使用變量(Python)的
我想用進口到另一個腳本(一旦它被稱爲,最初的劇本已經完成)但我需要第二個腳本來從原始打印一個變量。
所以,我可以導入第二個腳本,並使用打印正常,但是如果我嘗試並導入原來的劇本,所以我可以訪問變量..
但如果我這樣做,它只是給我一個錯誤:
Traceback (most recent call last):
File "C:\Users\luke\Desktop\k\startGame.py", line 2, in <module>
import Storyline
File "C:\Users\luke\Desktop\k\Storyline.py", line 1, in <module>
import startGame
File "C:\Users\luke\Desktop\k\startGame.py", line 56, in <module>
Storyline.startGame1()
AttributeError: 'module' object has no attribute 'startGame1'
我試圖打印:
print ("I see you have picked " + startGame.currentPokemon)
,我稱它是這樣的:
Storyline.startGame1()
和currentPokemon是
currentPokemon = inputKK
(InputKK是起動器口袋妖怪的輸入)
有沒有辦法做到這一點?是的,我正在做Python中的口袋妖怪遊戲,但它是不使用真實姓名口袋妖怪版本..
故事情節腳本:
import startGame
def startGame1():
print ("Welcome to the H.Q of I.O.D")
print ("I am Professor Steel.")
print ("I see you have picked " + startGame.currentPokemon)
startGame腳本:
import Storyline
inputKK = input("Choose from, 'Craigby', 'Robinby' or 'KKby' ")
if(inputKK == "Craigby"):
print("Craigby is a electric type.")
print("Craigby: Attack = 7, Defence = 3, Health = 6, Speed = 12")
if(inputKK == "Robinby"):
print("Robinby is a fire type.")
print("Robinby: Attack = 6, Defence = 5, Health = 7, Speed = 7")
if(inputKK == "KKby"):
print("KKby is a water type.")
print("KKby: Attack = 5, Defence = 8, Health = 11, Speed = 5")
print("")
os.system('cls')
currentPokemon = inputKK
counter = 0;
while(counter < 1):
print("Welcome to pokeby.")
print("Type S for [STORYLINE]")
print("Type R for pokemon in the field [CURRENT IS GRASS] ")
print("Type Q for [QUIT]")
inputMainMenu = input("S/R/Q ...")
if(inputMainMenu == "S"):
os.system('cls')
counter = counter + 2
Storyline.startGame1()
if(inputMainMenu == "R"):
os.system('cls')
counter = counter + 2
if(inputMainMenu == "Q"):
os.system('cls')
inputExit = input("Are you sure you want to quit? Y/N ")
if(inputExit == "Y" or inputExit == "y"):
print("K")
else:
counter = counter + 1
你將來需要一個更具描述性標題。也許是下一次的實際問題? – dckuehn
請將'startGame.py'的內容和'Storyline.py'中的函數列表發佈 – inspectorG4dget
將其更改爲更合適的內容,雖然不能真正描述它.. – user2913720