input file format

E

Etay

Hi all,

I am trying to write a Python script which will read the output file
of a numerical model, and then copy some of that information into a
new file in a new format. The output file of the numerical model is
basically

54321 # number of points
1234 # number of time steps

__a whole bunch of lines with info I don't need__

[TIMESTAMP] 001
1 10 10
2 10 11
3 11 11
etc... in the format: Point# X Y for all 54321 points
[TIMESTAMP] 002
1 13 13
2 14 13
etc... for all 54321 points

and so for each of the 1234 time steps

I would like to be able to save the number of points and time steps,
then move all the time stamped data into a new file, but it needs to
be written there as [ Pt# Y X ].

Is there some simple way to skip over the lines I don't need, and then
inform Python about the format of the lines with the data I do need
within a loop?

Thanks!
Etay
 
S

Steven D'Aprano

Is there some simple way to skip over the lines I don't need, and then
inform Python about the format of the lines with the data I do need
within a loop?

Yes. It's called "programming" :)

f = open('some file')
for line in f:
if some_condition(line):
continue # skip the line
process(line)
f.close()

some_condition can be anything you like. You just have to write the code to
make it so.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top