[python-uk] Reading a file of tab-separated values

Alexander Harrowell a.harrowell at gmail.com
Fri Nov 16 16:05:41 CET 2007


On Nov 16, 2007 2:31 PM, Tim Head <betatim at gmail.com> wrote:
> On 16/11/2007, Alexander Harrowell <a.harrowell at gmail.com> wrote:
> > On Nov 16, 2007 8:57 AM, Mark Summerfield <mark at qtrac.eu> wrote:
> > > On 2007-11-16, Jeremy Nicoll - pyuk wrote:
> > > > Is there a simple way to read a whole (modest sized, parameter) file of
> > > > lines of tab-separated lines into one Python data-structure?

>
> Like so?
>
> import csv
>
> input = csv.StringIO('Hello, World\tThe Spanish inquisition\tis coming
> to town, tomorrow\t(1,2,3,4)')
> reader = csv.reader(input, delimiter="\t")
>
> for line in reader:
>    print line
>

I was thinking more like ("Data","more data","even more data"),
("data", "data", "yet further data"), ("you", "get", "the", "picture")
to
("Data", "more data", "even more data")
(etc, etc)
(etc)


More information about the python-uk mailing list