0

I have to perform several experiments in order to analyse certain results for a class assignment. For each result, I have to run a line of code by varying the parameters from terminal. I was wondering if there is a way to automate this and thus save me the trouble of running the program and changing the values each time. Attached is the line of code that I have to execute each time:

teaa/examples/scripts/run-python.sh teaa/examples/python/rf_mnist.py \
         --numTrees 10 --maxDepth 7 --pcaComponents 40

I would like these lines of code to be executed n times automatically and that in each execution, the parameters 'numTrees, maxDepth and pcaComponents' change in a set range of values.

I have not really tried any solutions yet. I have never programmed in terminal and I have no idea where to start.

Nic3500
  • 8,144
  • 10
  • 29
  • 40
PicaPython
  • 101
  • 2
  • 1
    Duplicate of https://stackoverflow.com/questions/29790877/how-to-run-a-command-multiple-times-with-different-parameters (there are probably better duplicates; this is a common FAQ). – tripleee Nov 07 '22 at 19:25

1 Answers1

1

For more involved process operations, one should use the subprocess module in stdlib Python... but if you just want a one-off run of this command line, you can just use plain old os.system function - The followin code:

import os

for nt in range(1,21):                                                                                                                                                                                                                                        
    for md in range(1,11):
        for pc in range(20,100,10):
            os.system(f'teaa/examples/scripts/run-python.sh teaa/examples/python/rf_mnist.py  --numTrees {nt} --maxDepth {md} --pcaComponents {pc}')

will run your program for numTrees = 1,2...20, maxDepth = 1,..10 and pcaComponents = 20,...90

Alberto Garcia
  • 324
  • 1
  • 11