hhh
hhh

Reputation: 52840

Clarification needed about Python CSV file format parsing

Format is like:

CHINA;2002-06-25 00:00:00.000;5,60
CHINA;2002-06-26 00:00:00.000;5,32
CHINA;2002-06-27 00:00:00.000;5,31

and I try to use Python's CSV tools to parse it but cannot understand the paragraph, source:

And while the module doesn’t directly support parsing strings, it can easily be done:

import csv
for row in csv.reader(['one,two,three']):
    print row

Could someone clarify the line ['one,two,three']? How would you use it with format A;B;C?

Upvotes: 0

Views: 254

Answers (1)

Ned Batchelder
Ned Batchelder

Reputation: 375564

The docs you quote are talking about the difference between parsing csv data stored in a file, and csv data stored in a string. It doesn't have to do with the format of the data.

You should be able to read your data with something like:

import csv
csv_reader = csv.reader(open('data.csv', 'rb'), delimiter=';')
for row in csv_reader:
    # do something with row....

Upvotes: 3

Related Questions