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.(adsbygoogle = window.adsbygoogle || []).push({});

Output:Code (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]

Code (Text):[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

**Physics Forums | Science Articles, Homework Help, Discussion**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Python [Python] Why does this loop execute 4 times?

Loading...

Similar Threads for Python does loop |
---|

Python for vector files |

Practicing Python and R at the same time |

Python (VPython) Can someone help me with my orbit simulator? |

Python Create a sign-out sheet in Python |

Python What does this Python program do? |

**Physics Forums | Science Articles, Homework Help, Discussion**