[Numpy-discussion] Reading footer lines

Resmi l.resmi@gmail....
Tue Aug 13 07:20:05 CDT 2013


Hi,

I've a list of long files of numerical data ending with footer lines
(beginning with #). I am using numpy.loadtxt to read the numbers, and
loadtxt ignores these footer lines. I want the numpy code to read one of
the footer lines and extract words from it. Is there a way to use loadtxt
for this? If there weren't many files I could have used the line
number (which keep varying between the files) of the footer line along with
*linecache.*
Nevertheless there should be a generic way to do this in numpy?

As a workaround, I've tried using os.system along with grep. And I get the
following output :

*>>> os.system("grep -e 'tx' 'data.dat' ")*
* ## tx =    2023.06 *
*0*

Why is there a 0 in the output? The file has no blank lines.

Since I want the value 2023.06 in the numpy code for later use I tried to
pipe the output to a variable:-
*test = os.system(command)*
But that isn't working as *test* is getting assigned the value 0.
Tried *subprocess.call(['grep','-e','tx','data.dat'])* which is also ending
up in the same fashion.

It'll be great if I can get to know (i) a way to read the footer lines (ii)
to sort out the operation of os.system and subprocess.call output
processing.

Thanks,
Resmi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20130813/c4bd3aa7/attachment.html 


More information about the NumPy-Discussion mailing list