- Import the subprocess module:
import subprocess
- Design the command line. Generally, this should be tested at the OS prompt to be sure that it does the right things. We've shown an example of the command.
- Define a generator for the various commands to be executed. Each command can be built as a sequence of individual words. The original shell command is split on spaces to create the sequence of words:
def command_iter(files): for n in range(files): filename = 'game_{n}.yaml'.format_map(vars()) command = ['python3', 'ch13_r05.py', '--samples', '10', '--output', filename] yield command
This generator will yield a sequence of command strings. A client can use a for statement to consume each of the generated commands.