How to Loop Batch Processing in Python
Python loops let you iterate through a group of batch processes, perform an action on a process and display output to the user. The loop structure helps when you have several processes you want to run, and so do not need to run each process manually. If any errors occur, the preceding processes run, so only the current iteration fails during the loop.
Instructions
-
-
1
Open your Python editor and open the source code file you want to use to create the batch loop process.
-
2
Add the batch system libraries. Copy and paste the following code to the top of the file to import the libraries:
import sys
-
-
3
Create the loop. You can have the loop do any type of processing for your batches. The following code starts the loop:
for i in range(1, len(sys.argv)):
This statement uses i to iterate through each process. The process input is determined by the argument value, which is set as the argv variable.
-
4
Process the batches. For instance, the following code uploads files to a path, but you can use any code that manipulates the batch processes:
file = sys.argv[i]
uploaded = Image.open(file)
-
1