call one python script from within another

Dave Kuhlman dkuhlman at rexx.com
Tue Jul 15 16:58:57 EDT 2003


hokiegal99 wrote:

> Irmen de Jong <irmen at -NOSPAM-REMOVETHIS-xs4all.nl> wrote in
> message news:<3f0f40b9$0$49103$e4fe514c at news.xs4all.nl>...
>> Tubby Tudor wrote:

[snip]

>> def main():
>>      ....  body of your code here ....
>> 
>> 
>> main()               # run code in one
>> two.main()   # run code in two
>> three.main() # run code in three
>> ------------------
>> 
>> Will this do?
> 
> 
> Yes, this works. Thanks for the tip!

Note, however, that if the main() function in module two or three
uses command line paramters, you may have to trick it as follows:

  import sys

  main()               # run code in one
  sys.argv = ['junk', 'argval1', 'argval2']
  two.main()   # run code in two
  sys.argv = ['junk', 'argval3', 'argval4']
  three.main() # run code in three

By the way, I just tried this.  It works.

But, take a look at the main function in modules two and three.
It may be just as easy to call the function(s) it calls.

 - Dave

-- 
Dave Kuhlman
http://www.rexx.com/~dkuhlman
dkuhlman at rexx.com




More information about the Python-list mailing list