string split

Benjamin Kaplan benjamin.kaplan at case.edu
Fri Jan 9 15:39:54 EST 2009


On Fri, Jan 9, 2009 at 3:26 PM, Leland <lelandpeng at gmail.com> wrote:

> Hi,
>
> I have some formatted strings that I'd like to split and get the
> meaningful data, here is the example of the string format. The big
> difference of these two line are the second double quote set at the
> second line
> 100-01001-001,"Diode,Small Signal,SOT-23",1,D46,
> 100-01004-001,"Diode,High Voltage General Purpose,600mA,200V,SOT-23",
> 3,"D24,D72,D104",
>
> I want to split the string into the following format:
> '100-01001-001', 'Diode,Small Signal,SOT-23', '1', 'D46'
> '100-01004-001', 'Diode,High Voltage General Purpose,600mA,
> 200V,SOT-23', '3', 'D24,D72,D104'
>
[snip code]


This looks like a CSV file to me. If that is the case, it is easier to use
the built-in csv module than to try to write your own parser.


http://docs.python.org/library/csv.html#module-csv
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090109/c2cfad3a/attachment-0001.html>


More information about the Python-list mailing list