Lorenzo's help enabled a fix to UTF8 support in csv.writer in python bom generators.

This commit is contained in:
Dick Hollenbeck
2013-09-19 18:50:30 -05:00
parent c7531d6c38
commit 1e8430d53d
3 changed files with 49 additions and 28 deletions
@@ -47,15 +47,22 @@ columns = ['Item', 'Qty', 'Reference(s)', 'Value', 'LibPart', 'Footprint', 'Data
# Create a new csv writer object to use as the output formatter
out = csv.writer(f, lineterminator='\n', delimiter=',', quotechar='\"', quoting=csv.QUOTE_MINIMAL)
# override csv.writer's writerow() to support utf8 encoding:
def writerow( acsvwriter, columns ):
utf8row = []
for col in columns:
utf8row.append( str(col).encode('utf8') )
acsvwriter.writerow( utf8row )
# Output a set of rows as a header providing general information
out.writerow(['Source:', net.getSource()])
out.writerow(['Date:', net.getDate()])
out.writerow(['Tool:', net.getTool()])
out.writerow(['Component Count:', len(components)])
out.writerow([])
out.writerow(['Individual Components:'])
out.writerow([]) # blank line
out.writerow(columns)
writerow( out, ['Source:', net.getSource()] )
writerow( out, ['Date:', net.getDate()] )
writerow( out, ['Tool:', net.getTool()] )
writerow( out, ['Component Count:', len(components)] )
writerow( out, [] )
writerow( out, ['Individual Components:'] )
writerow( out, [] ) # blank line
writerow( out, columns )
# Output all the interesting components individually first:
row = []
@@ -74,16 +81,16 @@ for c in components:
for field in columns[7:]:
row.append( c.getField( field ) );
out.writerow(row)
writerow( out, row )
out.writerow([]) # blank line
out.writerow([]) # blank line
out.writerow([]) # blank line
writerow( out, [] ) # blank line
writerow( out, [] ) # blank line
writerow( out, [] ) # blank line
out.writerow(['Collated Components:'])
out.writerow([]) # blank line
out.writerow(columns) # reuse same columns
writerow( out, ['Collated Components:'] )
writerow( out, [] ) # blank line
writerow( out, columns ) # reuse same columns
@@ -121,6 +128,6 @@ for group in grouped:
for field in columns[7:]:
row.append( net.getGroupField(group, field) );
out.writerow( row )
writerow( out, row )
f.close()