On Mon, 08 Jun 2009 17:29:12 +0100, Steven D'Aprano <st...@remove-this-cybersource.com.au> wrote:

On Mon, 08 Jun 2009 18:13:50 +0200, Francesco Pietra wrote:

I come 'naked', which is unusual and unfair.

???

Yeah, I had to go and scrub my brain out :-)

Assuming no DIHED value will ever be split over two lines:


data = open(filename)
values = []
for line in data:
    if line and line.strip():  # ignore blanks
         words = line.strip().split()
         try:
             i = words.index("DIHED")
         except IndexError:

Should be ValueError, not IndexError.

             continue
         values.append(float(words[i+2]))
mean = sum(values)/len(values)


should do the job.

You don't need the second strip(),
        words = line.split()
should be sufficient.

(And we're back to the 'naked' bit again...)

--
Rhodri James *-* Wildebeeste Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to