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

Ashley Booth abooth at stanford.edu
Tue Sep 11 00:40:49 CEST 2007


I am trying to create a script that will get files from a directory
that the user specifies, then feeds the relevant input and output
(which are input and output paths) into another python script whose
path is also given by the user. I'm pretty lazy after all and I would
rather spend my time making tools than doing the busy-work myself.

So far I can get it to read the directory fine but it ends up just
opening the script I want the files to be fed into instead of giving
it the input and output to run and running it. Any ideas?

Here is what I have so far:

import sys, os

indir = raw_input('input directory path ') # input directory
script1 = os.system(raw_input('python script path '))

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


If this is going to be too complicated, I would at least be happy with
how to tack on the list directory stuff to then of the script1- it
would not be a stand alone script but at least it would work. I tired
to do that too but it only processed the first file in the directory
instead of all of them.


Thanks!


More information about the Tutor mailing list