Hi, You can use literal_eval from ast package.
>>> from ast import literal_eval >>> list(literal_eval("'aa','bb','cc'") this will return ['aa', 'bb', 'cc'] Thanks, Anoop Thomas Mathew atm ___ Life is short, Live it hard. On 14 June 2012 12:28, Shambhu Rajak <shambhu.ra...@kpitcummins.com> wrote: > This will do you job: > > >>> a = 'AAA,"BBBB,CCCC,DDDD",EEE,FFF,GGG' > >>> b = [] > >>> for x in a.split(','): > ... if (x.find("\"") > -1): > ... x = x.strip("\"") > ... b.append(x) > > If you want reduce the lines of code u can go for this option: > b = [x.strip("\"") for x in a.split(',')] > > > So Just Cheerz, > -Shambhu > > -----Original Message----- > From: bruce g [mailto:bruceg113...@gmail.com] > Sent: 14/06/2012 8:00 AM > To: python-list@python.org > Subject: string to list > > 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'] > > Thanks, > Bruce > > > -- > http://mail.python.org/mailman/listinfo/python-list >
-- http://mail.python.org/mailman/listinfo/python-list