Re: Extract value and average

2009-06-09 Thread Glauco
Francesco Pietra ha scritto: I come 'naked', which is unusual and unfair. However, I find it difficult to give a correct start. The files consist, among other things, of a huge number of blocks of the type NSTEP = 1000 TIME(PS) = 152.000 TEMP(K) = 298.54 PRESS =89.4 Etot =

Re: Extract value and average

2009-06-08 Thread Tim Chase
Tim Chase wrote: I would like to extract values corresponding to variable DIHED (here 4660.1650) and getting also the mean value from all DIHED. To just pull the DIHED values, you can use this: import re find_dihed_re = re.compile(r'\bDIHED\s*=\s*([.-e\d]+)', re.I) total = count = 0

Re: Extract value and average

2009-06-08 Thread Scott David Daniels
Steven D'Aprano wrote: ... 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() words = line.split() # does the same as above try:

Re: Extract value and average

2009-06-08 Thread Rhodri James
On Mon, 08 Jun 2009 17:29:12 +0100, Steven D'Aprano 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

Re: Extract value and average

2009-06-08 Thread MRAB
Steven D'Aprano wrote: On Mon, 08 Jun 2009 18:13:50 +0200, Francesco Pietra wrote: I come 'naked', which is unusual and unfair. ??? However, I find it difficult to give a correct start. The files consist, among other things, of a huge number of blocks of the type NSTEP = 1000 TIME(

Re: Extract value and average

2009-06-08 Thread Tim Chase
I would like to extract values corresponding to variable DIHED (here 4660.1650) and getting also the mean value from all DIHED. To just pull the DIHED values, you can use this: import re find_dihed_re = re.compile(r'\bDIHED\s*=\s*([.-e\d]+)', re.I) total = count = 0 for line in file('fi

Re: Extract value and average

2009-06-08 Thread Steven D'Aprano
On Mon, 08 Jun 2009 18:13:50 +0200, Francesco Pietra wrote: > I come 'naked', which is unusual and unfair. ??? > However, I find it > difficult to give a correct start. The files consist, among other > things, of a huge number of blocks of the type > > > NSTEP = 1000 TIME(PS) = 152.

Re: Extract value and average

2009-06-08 Thread MRAB
Francesco Pietra wrote: I come 'naked', which is unusual and unfair. However, I find it difficult to give a correct start. The files consist, among other things, of a huge number of blocks of the type NSTEP = 1000 TIME(PS) = 152.000 TEMP(K) = 298.54 PRESS =89.4 Etot = -1