Extract value and average
rhodri at wildebst.demon.co.uk
Mon Jun 8 12:57:41 EDT 2009
On Mon, 08 Jun 2009 17:29:12 +0100, Steven D'Aprano
<steve at 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()
> i = words.index("DIHED")
> except IndexError:
Should be ValueError, not IndexError.
> 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
More information about the Python-list