return value from one python script to another

Ok, if I understand you correctly you want to:

  • pass an argument to another script
  • retrieve an output from another script to original caller

I’ll recommend using subprocess module. Easiest way would be to use check_output() function.

Run command with arguments and return its output as a byte string.

Sample solution:

import sys
import subprocess
s2_out = subprocess.check_output([sys.executable, "", "34"])
print s2_out

import sys
def main(arg):
    print("Hello World"+arg)

if __name__ == "__main__":

Leave a Comment