在 GenericFunctions.py 中,我声明了全局变量,并在 Login_CSA.py
中导入了这些变量但在使用这些变量编写任何打印语句时,它会显示错误消息,如
“导入时未定义的变量”
GenericFunctions.py 中的global g_TargetEnvironment
global g_TargetRegion
global g_TargetSystem
global g_TCDataSheet
global g_Remarks
Login_CSA.py import GenericFunctions
def Login_CSA(p_TargetEnvironment, p_TargetSystem, p_TargetRegion, p_TCDataSheet, p_TCOutputFile, p_TargetoptLevel, p_TCaseID, p_TCDescription):
#Script to clear all the global variables declared
nullifyglobal=GenericFunctions.fn_NullifyGlobal()
#Script to close any existing firefox is there or not
closeexistingfirefox=GenericFunctions.fn_CloseExistingFFBrowser()
GenericFunctions.g_TargetEnvironment = p_TargetEnvironment
print "g_TargetEnvironment : ", GenericFunctions.g_TargetEnvironment
GenericFunctions.g_TargetSystem = p_TargetSystem
print "g_TargetSystem : " , GenericFunctions.g_TargetSystem
GenericFunctions.g_TargetRegion = p_TargetRegion
GenericFunctions.g_TCDataSheet = p_TCDataSheet
GenericFunctions.g_TCDataSheet = GenericFunctions.g_TCDataSheet+".xlsx"
我在“print”g_TargetEnvironment:“,GenericFunctions.g_TargetEnvironment”,“”GenericFunctions.g_TCDataSheet = GenericFunctions.g_TCDataSheet +“中收到错误.xlsx”“”“这句话
你们可以帮助我解决这个问题答案 0 :(得分:1)
更改
global g_TargetEnvironment
global g_TargetRegion
global g_TargetSystem
global g_TCDataSheet
global g_Remarks
为:
g_TargetEnvironment = None
g_TargetRegion = None
g_TargetSystem = None
g_TCDataSheet = None
g_Remarks = None