Reading csv file

Bernd Nawothnig Bernd.Nawothnig at t-online.de
Tue Dec 17 09:30:23 CET 2013


On 2013-12-17, Igor Korot wrote:
> Hi, ALL,
> Is there a better way to do that:
>
> def Read_CSV_File(filename):
>       file = open(filename, "r")
>       reader = csv.DictReader(file)
>       line = 1
>       for row in reader:
>           if line < 6:
>              reader.next()
>              line++
> # process the CSV

#v+
def Read_CSV_File(filename):
    with open(filename) as f:
        for line,row in enumerate(csv.DictReader(f)):
            if line >= 6:
                # process the CSV
#v-




Bernd

-- 
no time toulouse



More information about the Python-list mailing list