是否有可能在一个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()' –