handling tabular data in python--newbie question

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Wed Aug 29 09:02:00 EDT 2007


hyena a écrit :
> Hi,
>   Just jump in python few days. I am wondering how to store and index a 
> table in python effectively and easily.I think the basic data types are not 
> very straight foward to handle a table (eg, from csv or data base.)

What make you think such a thing ?

>   I have a csv file, the first row of it is column names and the rest rows 
> are data. There are some tens of columns and hundreds rows in the file. I am 
> planning to use the column names as variables to access data, currently I am 
> thinking of using a dictionary to store this file but did not figure out a 
> elegant way to start.

Use the csv module - it's in the standard lib. It has an option to use 
dicts to allow keyed access to 'columns' (look for csv.DictReader).

Anyway, if you have anything complex to do with your data, you'd 
probably better use SQLite (possibly using csv module to help importing 
your data).

My 2 cents...



More information about the Python-list mailing list