- #1
Hercuflea
- 596
- 49
I've written a code which reads in an input file and extracts a number which represents a grid size, from lines in the file which can contain arbitrary characters. The extraction of the data seems to be working, but for some reason the loop executes 4 times and then moves on to the next function in my code...Why does my loop execute 4 times? I've been stuck on this for a while now.
Output:
Python:
def BOUTinp_search():
with open('BOUT.inp', 'r') as boutinput:
for line in boutinput:
if '[mesh]' in line:
print '\nFound mesh options.'
continue
elif 'nx =' in line:
xnumpts = int(filter(str.isdigit, line))
print('Recovered number of x gr'
'id points.')
print 'x grid size: ', xnumpts
continue
elif 'ny =' in line:
ynumpts = int(filter(str.isdigit, line))
print('Recovered number of y gr'
'id points.')
print 'y grid size: ', ynumpts
continue
elif 'dx =' in line:
dx = float(filter(str.isdigit, line))
print 'Recovered x spacing.'
print 'x grid spacing: ', dx
continue
elif 'dy =' in line:
dy = float(filter(str.isdigit, line))
print 'Recovered y spacing.'
print 'y grid spacing: ', dy
continue
return [xnumpts, ynumpts, dx, dy]
Output:
Code:
[me@dir]$ python file.py
Found mesh options.
Recovered number of x grid points.
x grid size: 260
Recovered number of y grid points.
y grid size: 1
Recovered x spacing.
x grid spacing: 2.0
Recovered y spacing.
y grid spacing: 1.0
Found mesh options.
Recovered number of x grid points.
x grid size: 260
Recovered number of y grid points.
y grid size: 1
Recovered x spacing.
x grid spacing: 2.0
Recovered y spacing.
y grid spacing: 1.0
Found mesh options.
Recovered number of x grid points.
x grid size: 260
Recovered number of y grid points.
y grid size: 1
Recovered x spacing.
x grid spacing: 2.0
Recovered y spacing.
y grid spacing: 1.0
Found mesh options.
Recovered number of x grid points.
x grid size: 260
Recovered number of y grid points.
y grid size: 1
Recovered x spacing.
x grid spacing: 2.0
Recovered y spacing.
y grid spacing: 1.0
Last edited by a moderator: