I have a list and I want to extract to another list the data that exist between top_row and bottom_row.
I know the top_row and also that the bottom_row corresponds to data[0] = last integer data (next row is made of strings, but there are also rows with integers which I’m not interested).
I’ve tried several things, but w/o success:
for row,data in enumerate(fileData):
if row > row_elements: #top_row
try:
n = int(data[0])
aux = True
except:
n = 0
while aux: #until it finds the bottom_row
elements.append(data)
The problem is that it never iterates the second row, if I replace while with if I get all rows which the first column is an integer.
fileData is like:
*Element, type=B31H
1, 1, 2
2, 2, 3
.
.
.
359, 374, 375
360, 375, 376
*Elset, elset=PART-1-1_LEDGER-1-LIN-1-2-RAD-2__PICKEDSET2, generate
I’m only interested in rows with first column values equal to 1 to 360.
Many thanks!
If no exception is thrown in the
trypart, then you basically end up with an endless loop, given thatauxwill always beTrue.I’m not perfectly sure what you are doing in your code, given the way the data looks isn’t clear and some things are not used (like
n?), but in general, you can stop a running loop (bothforandwhileloops) with thebreakstatement:So in your case, I would guess something like this would work: