unix - Loop for interpret the python script (.py) -


i'm beginner python. question might basic, cannot figure out. want run following command 100 times in variable "num" runs 0 through 99.

python test.py input_num.txt -i 5 --cor_file=output_num.txt

for example:

python test.py input_0.txt -i 5 --cor_file=output_0.txt

python test.py input_1.txt -i 5 --cor_file=output_1.txt

... :::

python test.py input_99.txt -i 5 --cor_file=output_99.txt

i know have write script running loop, cannot figure out yet. if have recommendation, nice.

i tried write script called main.py containing following commands, didn't work.

#!/usr/bin/env python  import test ext_str = '.txt' inp = 'input_' out = 'output_'  num in range(0,99):       inp += 'num'   inp_str = inp + ext_str    out += 'num'   out_str = out + ext_str    python test.py inp_str -i 5 --cor_file=out_str 

thank much.

best, pim

in case need call python interpreter on various files, e.g. need call "python" shell command, means have create shell script (and not python script, python code way complicated in case):

for in {0..99}     python test.py input_$i.txt -i 5 --cor_file=output_$i.txt done 

put above code in ".sh" file don't forget "chmod +x ", run ./.sh (given in current directory).

n.b.: if need references on bash scripting : linux shell scripting tutorial


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -