Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Variable substitution in function call

Trying to substitute a variable in a function call.

Post variable substitution, I have also tried to use subprocess .

Python version - 2.6.6 (Yes, its old I know)

import subprocess
from subprocess import PIPE,Popen

class test():
def __init__(self,a,b):
    self.a = a
    self.b = b

@staticmethod
def printvalues():
    print ("Function printvalues called")

env1_print = test(5,10)
env1_print.printvalues() # (1) . Works

envvar = "env1"
"%s_print.printvalues()"%(envvar) # 2. Doesnt execute
print("%s_print.printvalues()"%(envvar)) # Matches (1) exactly
runthis = ('"%s_print.printvalues()"%(envvar)')
subprocess.call(['runthis'], stdout=PIPE, stderr=PIPE)

Expected results: Variable substitution to work in the function call and function call to execute

Actual results: Variable substitution works, works, but function call doesnt execute.

Comments