Yes I agree that it'd be cleaner to import the second script and call it. 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 sys.exit(5) 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.: Test.py ------- import sys Def test(): return(5, "Junk") if __name__ == __main__: test() 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 ... Cheers Hans -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 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. 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 _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor