This will all get read as strings, and you'll have to do the data conversion
yourself. For each row (if it's all data), you should be able to
something like:
for row in reader:
row = map(float, row)
You could get more sophisticated and ensure that the data should actually
be converted using regular expressions.
import re
isfloat = re.compile('[+-]?[0-9]*\.?[0-9]+')
for row in reader:
row = [float(el) if isfloat.match(el) else el for el in row]
Hope this helps,
Andrew
On Fri, Feb 22, 2008 at 1:24 PM, Peter Perez <plpd00@...> wrote:
>
>
>
>
>
>
> Hi all,
>
> I need to read a tab-delimited file with numeric data in columns, and
> then create an array with each of the columns of the file. Although I
> am a newbie in Python, I thought it would be as easy (or easier) than
> in Matlab, but that doesn't seem to be the case. I haven't found any
> way to do that, neither in the tutorials nor the online documentation.
> So far, I only know how to do this:
>
> filename = 'ptrace.csv'
> reader = csv.reader(open(filename,'r'),dialect='excel-tab')
>
> But I don't know how to load the numeric data into an array that Python
> can manipulate. Could somebody help me please? Thank you very much for
> your kind attention. Best regards, Peter
>
>
--
Andrew Gwozdziewycz
apgwoz@...
http://www.apgwoz.com | http://www.photub.com