[Numpy-discussion] fromfile() for reading text (one more time!)

josef.pktd@gmai... josef.pktd@gmai...
Sat Jan 23 13:04:24 CST 2010


On Sat, Jan 23, 2010 at 1:53 PM, Christopher Barker
<Chris.Barker@noaa.gov> wrote:
> alan@ajackson.org wrote:
>> it doesn't support the reasonable
>> (IMHO) behavior of treating quote delimited strings in the input file as a
>> single field.
>
> I'd use the csv module for that.
>
> Which makes me wonder if it might make sense to build some of the numpy
> table-reading stuff on top of it...
>
> -Chris

csv was also my standard module for this, it handles csv dialects and
unicode (with some detour), but having automatic conversion in
genfromtext is nicer.

>>> reader = csv.reader(open(r'C:\Josef\work-oth\testdata.csv','rb'), delimiter=' ')
>>> for line in reader:
...     print line
...
['Greenmantle', '2.5', '650', '16.083']
['Carnethy', '6', '2500', '48.35']
['Craig Dunain', '6', '900', '33.65']
['Ben Rha', '7.5', '800', '45.6']
['Ben Lomond', '8', '3070', '62.267']
['Goatfell', '8', '2866', '73.217']
['Bens of Jura', '16', '7500', '204.617']
['Cairnpapple', '6', '800', '36.367']
['Scolty', '5', '800', '29.75']
['Traprain', '6', '650', '39.75']
['Lairig Ghru', '28', '2100', '192.667']

Josef

>
>
> --
> Christopher Barker, Ph.D.
> Oceanographer
>
> NOAA/OR&R/HAZMAT         (206) 526-6959   voice
> 7600 Sand Point Way NE   (206) 526-6329   fax
> Seattle, WA  98115       (206) 526-6317   main reception
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>


More information about the NumPy-Discussion mailing list