csv.reader problem tab-delimiter - newbie

Benjamin Kaplan benjamin.kaplan at case.edu
Tue Oct 21 13:09:22 EDT 2008


On Tue, Oct 21, 2008 at 12:26 PM, <hidding at uni-duesseldorf.de> wrote:

> Hi all,
>
> I use python 2.5 and want to read in a simple 5-columned, tab-
> delimited ascii file "dummy.txt" such as as
>
> 1  2    3.0    4     5.6
> 4  6    77     8.2  19
>
> I do
>
> import csv
> asciireader = csv.reader(open('dummy.txt'), delimiter='\t')
>
> array1 = []
> for entry in asciireader:
>  array1.append( entry )
>
> however when I then
>
> print array1
>
> then the array does only have two elements [1  2    3.0    4     5.6]
> and [4  6    77     8.2  19]. The tab-delimiter seems to have been
> totally ignored! This is bad because I want to do some maths with the
> numbers from the file later (after converting them into floats).
>
> Can someone help?
>

> Best regards,
>
> Bernhard
>


Make sure your text editor is using tabs and not spaces.

>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20081021/a8fab453/attachment-0001.html>


More information about the Python-list mailing list