[Tutor] Returning multiple values from a script

Hans Dushanthakumar Hans.Dushanthakumar at navman.com
Thu Jan 12 00:37:51 CET 2006

Yes I agree that it'd be cleaner to import the second script and call

The reason I'm keen to find a alternate method is that I have a whole
lot of scripts that were designed to run only as standalone scripts. ie
each of these scripts is not a "function" that I could just call from
another script. They are all of the format:

1) Test.py
import sys


Now I'm trying to write a master script that'd run each one of these
scripts. I'm sure it would have been a lot easier if the scripts were of
the following format. Unfortunately they are not.:

import sys

Def test():
    return(5, "Junk")

if __name__ == __main__:

Well if there is no other way I think I'll have to alter all the scripts
to be of the above format. Just wondering if anyone has any suggestions


-----Original Message-----
From: tutor-bounces at python.org [mailto:tutor-bounces at python.org] On
Behalf Of Kent Johnson
Sent: Thursday, 12 January 2006 12:06 p.m.
Cc: Python Tutor
Subject: Re: [Tutor] Returning multiple values from a script

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.


def findR():
   return 7, 'Hans'


import test

res = test.findR()
print res


> 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

Tutor maillist  -  Tutor at python.org

More information about the Tutor mailing list