从另一个函数Python调用变量

chr*_*ley -7 python

我试图调用一个变量用于另一个函数.该变量仅在另一个函数中,并未声明为全局变量.有谁知道如何调用其他变量.下面的代码显示了正在使用的'retval'变量,但它在另一个函数中声明.

def email_results():

    if make.retval > 0:
        os.system('python email_success.py')
    else: 
        os.system('python email_failure.py')

if __name__ == '__main__': myObject = email_results()
Run Code Online (Sandbox Code Playgroud)

谢谢

我声明的函数是:

def make():

    if os.path.exists(t):

        command = "export ROOTDIR="+rootDir+"; "
        command += "export PROJECT="+project+"; "
        command += "export BUILD_DIR=$ROOTDIR/$PROJECT/basebuild; "
        command += "export AD_EXEC_DIR=$BUILD_DIR/output_dev; "
        command += "export BLDTARGET=MVArm9; "
        command += "export PROFILE=release; "
        command += "cd $ROOTDIR/$PROJECT; "
        command += "make > "+logFileName+" 2>&1"

        print "The command that I will be executing is:"
        print command

    #executing make command

        retval = os.system(command)
        print "retval=", retval 
        return retval

    if __name__ == '__main__': myObject = make()
Run Code Online (Sandbox Code Playgroud)

S.L*_*ott 7

make.retval是(我猜你的模糊问题)另一个函数的结果make,由于某种原因不会返回retval.

做这个

def make( ):
    etc. 
    return retval

def email_results( retval ):
    etc.

if __name__ == "__main__":
    retval= make()
    email_results( retval )
Run Code Online (Sandbox Code Playgroud)

请找一本关于编程的好书并阅读它.你在编程的基本概念方面遇到了问题,而不是Python.