<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.0.6603.0">
<TITLE>How to pass variables between scripts?</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->
<BR>

<P><FONT SIZE=2 FACE="Arial">Dear list,</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">I am an absolute newbie to python and would appreciate your help very much  :)</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">I am trying to write a little python script that wraps a set of external scripts. The external scripts are either also written in python or are simple bash scripts. My wrapping script should be able to send an argument to the first script, to execute it, to read its results and to send them then as arguments into the next script.</FONT></P>

<P><FONT SIZE=2 FACE="Arial">This is the first part that I have written so far: </FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">#! /usr/local/bin/python</FONT>

<BR><FONT SIZE=2 FACE="Arial"># test_exec.py</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">import os, sys, glob</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">fileList = glob.glob('/data/*.ZIP')</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">for f in fileList:</FONT>

<BR>        <FONT SIZE=2 FACE="Arial">try: </FONT>

<BR>                <FONT SIZE=2 FACE="Arial">globvars = {'infile' : f}</FONT>

<BR>                <FONT SIZE=2 FACE="Arial">locvars = {}</FONT>

<BR>                <FONT SIZE=2 FACE="Arial">execfile('/scripts/second.py', globvars(), locvars)</FONT>

<BR>        <FONT SIZE=2 FACE="Arial">except IOError:</FONT>

<BR>                <FONT SIZE=2 FACE="Arial">exit(0)</FONT>

<BR>        <FONT SIZE=2 FACE="Arial">print locvars</FONT>
</P>
<BR>

<P><FONT SIZE=2 FACE="Arial">And this is what happens when calling test_exec.py</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial"> ./test_exec.py </FONT>

<BR><FONT SIZE=2 FACE="Arial">Traceback (most recent call last):</FONT>

<BR><FONT SIZE=2 FACE="Arial">  File "./test_exec.py", line 19, in ?</FONT>

<BR><FONT SIZE=2 FACE="Arial">    execfile('/scripts/second.py', vars(), results)</FONT>

<BR><FONT SIZE=2 FACE="Arial">TypeError: 'dict' object is not callable</FONT>
</P>
<BR>

<P><FONT SIZE=2 FACE="Arial">I tried already to modify the script in different ways but wasn't successful so far to make it running. Could you maybe help what I am missing? Further, I am not sure how the second python has to look like to actually read what is given in "globvars" and to sent its results into "locvars". </FONT></P>

<P><FONT SIZE=2 FACE="Arial">Or might os.popen* be a better option?  </FONT>
</P>

</BODY>
</HTML>