是否有可能在一個Python腳本中有多個全局變量?我可以在python腳本中有多個全局變量嗎?
import os,csv,random
def user():
global Forname
Forname = input('What is your forname? ').capitalize()
while True:
try:
global answerr
answerr = input('Welcome to the phone troubleshooting system '
'\nApple\nSamsung '
'\nOut of the following options enter the name of the device you own ').lower()
except ValueError:
continue
if answerr in ('apple','samsung'):
break
myfile = open(answerr+'_device.csv','r')
answer = input(Forname + ', do you have anymore problems? ').lower()
if 'yes' in answer:
#do whatever
else:
#do whatever
使用全局變量「answerr」我想開一個CSV文件,並指與他們的forName輸入的用戶,但我想通過高清之內我的代碼中多次使用它們功能。如果你不明白我在問什麼,我會提前道歉,鑑於我還是一名學校學生,我對編碼相對來說比較陌生。
更妙的是重命名功能名稱爲'get_forename_from_user()' –