How to pass variables between scripts?

Marcelo Ramos mramos at
Sat May 13 00:34:45 CEST 2006

Gross, Dorit (SDRN) escribió:
> Dear list,
> I am an absolute newbie to python and would appreciate your help very much
> :)
> 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.
> This is the first part that I have written so far: 
> #! /usr/local/bin/python
> #
> import os, sys, glob
> fileList = glob.glob('/data/*.ZIP')
> for f in fileList:
> 	try: 
> 		globvars = {'infile' : f}
> 		locvars = {}
> 		execfile('/scripts/', globvars(), locvars)
> 	except IOError:
> 		exit(0)
> 	print locvars
> And this is what happens when calling
>  ./ 
> Traceback (most recent call last):
>   File "./", line 19, in ?
>     execfile('/scripts/', vars(), results)
> TypeError: 'dict' object is not callable
> 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". 
> Or might os.popen* be a better option?  

You are calling the dictionary globvars as a function then the error. 
The fixed line is:

execfile('/scripts/', globvars, locvars)

What you want is the function globals().
Try putting this line in

print globals()['infile']

Using the dictionary returned by globals() you can make to 
read the contents of's globvars dictionary.
locvars is populated with the local variables of and that is 
what you want.


Marcelo Ramos
Fedora Core 5 | 2.6.16
Socio UYLUG Nro 125

More information about the Python-list mailing list