string split

Jerry Hill malaclypse2 at
Fri Jan 9 21:57:42 CET 2009

On Fri, Jan 9, 2009 at 3:39 PM, Benjamin Kaplan
> 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.

It should be as easy as this:

import csv

testfile = open('testfile.csv', 'w')
testdata = """100-01001-001,"Diode,Small Signal,SOT-23",1,D46,
100-01004-001,"Diode,High Voltage General

infile = open('testfile.csv', 'r')
reader = csv.reader(infile)
for line in reader:
    print line

The output of that code is:

['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', '']

so line[0] is your part number, etc.


More information about the Python-list mailing list