tags:

views:

151

answers:

2

Hello,

I am trying to call a variable for use in another function. The variable is only in the other function and not declared as a global variable. Does anyone know how to call the other variable. The code below shows the 'retval' variable being used but it is declared in the other function.

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()

Thanks

The function I declare it in is:

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()
+8  A: 

Your make.retval is (I'm guessing from your vague question) the result of another function, make, which for some reason doesn't return retval.

Do this

def make( ):
    etc. 
    return retval

def email_results( retval ):
    etc.

if __name__ == "__main__":
    retval= make()
    email_results( retval )

Please find a good book on programming and read it. You're having problems with fundamental concepts of programming, not Python specifically.

S.Lott
+1  A: 

It should be make() not make.retval; the first is a function call, the second is an object member (sometimes called an attribute) reference. Since you defined make as a function, it is callable but does not have a member called retval.

Andrew McGregor