Currently Python reads each line of a file and executes a function doStep()
. This function is passed whatever is on the line being read.
data.txt
a
b
c
b
read.py
fin = open('data.txt')
for step in fin:
doStep(step)
Python will then execute
doStep(a)
doStep(b)
doStep(c)
doStep(b)
Question: If I want to define nested loops in data.txt, how should it be defined and parsed? The nesting and number of loop iterations should be defined in data.txt
For example, by reading data.txt I want to loop this 5 times
doStep('a')
doStep('b')
doStep('c')
and loop this 10 times
doStep('x')
doStep('y')
doStep('z')
and repeat everything 3 times (nesting).