csv.reader problem tab-delimiter - newbie

George Sakkis george.sakkis at gmail.com
Tue Oct 21 14:02:09 EDT 2008


On Oct 21, 1:44 pm, hidd... at uni-duesseldorf.de wrote:
> > Most likely the file is not tab delimited. If you used an editor to
> > produce dummy.txt, check whether it uses soft tabs and disable it
> > temporarily.
>
> > HTH,
> > George
> > Most likely the file is not tab delimited. If you used an editor to
> > produce dummy.txt, check whether it uses soft tabs and disable it
> > temporarily.
>
> > HTH,
> > George
>
> grrr thanks George, thanks Daniel, that's it. Works fine with real
> tabs. Now this brings me to a follow-up: I have not prepared the input
> ascii file, I just got if for post-processing (23 MB). Now it seems
> that I would have to replace all series of spaces in this file with
> real tabs at first.. How would you do that? Are there text editors
> capable of doing this?

If your file consists of numbers only, you don't even need csv; you
can read the whole file and convert it to floats in a single readable
line:

data = [map(float, line.split()) for line in open('dummy.txt')]

HTH,
George



More information about the Python-list mailing list