[Tutor] Returning multiple values from a script

Kent Johnson kent37 at tds.net
Thu Jan 12 00:05:36 CET 2006


Hans Dushanthakumar wrote:
> Hi,
>    Can a script return multiple values to the os?

Is there a reason why you have to call the second test.py using 
os.system()? I would write it to be imported and called.

test.py
------

def findR():
   return 7, 'Hans'


script1.py
---------

import test

res = test.findR()
print res

Kent

> 
> What I have in mind is something like the following:
> 
> 
> 1) Test.py
> -------
> import sys
> 
> r = 7
> sys.exit(r)
> # What I really want to do is something along the lines of sys.exit(r,
> "Hans")
> 
> 
> 
> 2) Script1.py (This script executes script test.py and prints out its
> exit code): 
> ----------
> import os
> 
> t = "test.py"
> res = os.system('"python test.py")
> print res



More information about the Tutor mailing list