[Numpy-discussion] How can Import DATA from a Fortran file

Olivier Delalleau shish at keba.be
Fri May 20 09:22:08 EDT 2011

StringIO(data_file_name) will not read your file, it will just allow you to
read the string data_file_name. You can probably just use
open(data_file_name) (and yes,you'll probably need to open it for each call
to genfromtxt).
Sorry my script didn't work, I definitely didn't expect it to work right
away, it was more to give you an idea of the kind of stuff you could do
manually. I'd expect it should be pretty straightforward to fix it. I
personally find it easier to write my own custom code to load such small
data files, rather than try to find the right parameters for an existing
function ;) (especially with mixed float / string dta).

-=- Olivier

2011/5/19 Aradenatorix Veckhom Vacelaevus <aradnix at gmail.com>

> Thanks both for your helping:
> I was checking the script fro Olivier but doesn't works yet, later I tried
> with the asciitable package but I also never could read any of my files
> (finally I decide create a single file for each case, it means to get 2
> arrays for each domain).
> I was reading a while about how to import data with genfromtxt in Numpy, it
> was very interesting because I have a lot of options for import data, I can
> skip headers and footers, I can import selected columns and other stuff, so
> I wanna use it for import my columns in each case and later get an output in
> a text file, how can I get it?
> My idea is to make something like:
> #!/usr/bin/env python
> #-*- coding:utf-8 -*-
> import numpy as np
> from StringIO import StringIO
> np.genfromtxt(StringIO(data_file_name), autostrip=True, skip_header=2,
> usecols=(1, 2, 3))
> np.genfromtxt(StringIO(data_file_name), autostrip=True, skip_header=2,
> usecols=(4, 5, 6))
> np.genfromtxt(StringIO(data_file_name), autostrip=True, skip_header=2,
> usecols=(-1))
> But I'm not sure how to use it, I have not experience importing that stuff,
> but also I don't know If I need to add a line at the beginning with
> data = StringIO(data_file_name)
> Could you help me once more?
> Regards:
> Aradnix
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110520/6ccf9f0c/attachment.html>

More information about the NumPy-Discussion mailing list