string to list

Peter Otten __peter__ at web.de
Thu Jun 14 03:19:19 EDT 2012


bruce g wrote:

> What is the best way to parse a CSV string to a list?
> 
> For example, how do I parse:
>     'AAA,"BBBB,CCCC,DDDD",EEE,FFF,GGG'
> to get:
>     ['AAA','BBB,CCC,DDDD','EEE','FFF','GGG’]

>>> import csv
>>> next(csv.reader(['AAA,"BBBB,CCCC,DDDD",EEE,FFF,GGG']))
['AAA', 'BBBB,CCCC,DDDD', 'EEE', 'FFF', 'GGG']

For multiple records: 

list(csv.reader(text.splitlines(True)))




More information about the Python-list mailing list