[Tutor] Making a python script to feed files into another pythonscript

Ashley Booth abooth at stanford.edu
Wed Sep 12 17:35:48 CEST 2007


Unfortunately I was confused by both responses I received. I have only
been working with Python for a week, so everything is new. Thanks for
your patience.

John- I was not sure what you meant by "command line". I took what you
said quite literally and created this:

indir = raw_input('input directory path ') # asks for input directory
script1 = raw_input('python script path ') # asks for path to desired script

for j in os.listdir(indir):
       input = os.path.join(indir,j)
       output = os.path.join(indir,j.split('rovctd')[0]+'.txt')
       os.system('python %s %s %s' % (script1, input, output)

which does not run and I was confused by all the % symbols. I think I
completely misinterpreted your comment.

Alan-I am confused about how to used the communicate() module. Could
you please give me an example?

the format should be(?):

communicate(input=None)

where input is the file path I want to give my child process (script1)
(what if I have two files paths I need to give it?- one for the input
file path and one for the output?

and I want to put PIPE and not None so that it will deliver that input?


What I was trying to say before at the end of my post:

> I would at least be happy with how to tack on the list
> directory stuff to THE END of the script1- it would not be a
> stand alone script but at least it would work.

In other words, instead of having a stand alone script that feeds
files into script1 (the program I want the files to be fed into-it
reformats files so it requires a file path input and output), could I
have script1 ask me for a directory instead of a specific input and
output file path as it does now. Then it would theoretically go
through and reformat each file in that directory, rename them and put
the formatted files back in that directory.

I hope that is clearer.

Thanks again!


More information about the Tutor mailing list