Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #3275

genfromtxt and comment identifier

From simona bellavista <afylot@gmail.com>
Newsgroups comp.lang.python
Subject genfromtxt and comment identifier
Date 2011-04-15 09:58 -0700
Organization http://groups.google.com
Message-ID <9954a3b4-7260-4d95-b0f0-a2c3aec14d7a@w7g2000pre.googlegroups.com> (permalink)

Show all headers | View raw


Hi All,

I have a problem with reading data from a file using genfromtxt of
numpy module.

I have prepared a minimal example similar to the ones presented in

http://docs.scipy.org/doc/numpy/user/basics.io.genfromtxt.html#splitting-the-lines-into-columns

The script is

import numpy as np
from StringIO import StringIO
file = open('esempio.dat')
for line in file.xreadlines() :
    if not line : break
    print line
    np.genfromtxt(StringIO(line), comments="#", delimiter=",")

I have a data file - esempio.dat - like the following:

#
# Skip me !
# Skip me too !
1, 2
3, 4
5, 6 #This is the third line of the data
7, 8
# And here comes the last line
9, 0
"""

The code is breaking at the first line, it looks like it doesn't
recognize # like comment identifier.

The error in the python interpreter is

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "esempio.py", line 7, in <module>
    np.genfromtxt(StringIO(line), comments="#", delimiter=",")
  File "/opt/numpy/1.5.1/lib/python2.6/site-packages/numpy/lib/
npyio.py", line 1174, in genfromtxt
    raise IOError('End-of-file reached before encountering data.')
IOError: End-of-file reached before encountering data.


It is clear that I haven't understood something, what am I doing
wrong?

Cheers

Back to comp.lang.python | Previous | NextNext in thread | Find similar


Thread

genfromtxt and comment identifier simona bellavista <afylot@gmail.com> - 2011-04-15 09:58 -0700
  Re: genfromtxt and comment identifier Peter Otten <__peter__@web.de> - 2011-04-15 19:20 +0200

csiph-web