[Tutor] how to read from a csv file?
Tim Golden
mail at timgolden.me.uk
Mon Oct 22 18:15:10 CEST 2007
pierre cutellic wrote:
> Hi, this is a module i wrote to catch some data from a csv file:
>
> ##########
> #module csv data reader
> # open a csv file and return its data
>
> import csv
> import sys
>
> def __init__(self):
>
Stop right there. You're confusing modules and
classes. A class has a (meaningful) __init__ method,
which is called when the class is instantiated. You
*can* have an __init__ in a module, but it doesn't
do anything special.
You really just want to rename __init__ to rawdata
and drop the redundant "return rawdata" function.
TJG
More information about the Tutor
mailing list