在python中导入全局变量时出错

时间:2013-11-06 05:41:55

标签: python python-2.7

我已经采用了两个python模块,e。 GenericFunctions.py Login_CSA.py

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”“”“这句话

你们可以帮助我解决这个问题

1 个答案:

答案 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