Skip to content

Commit 9fa62d8

Browse files
committed
[tools/xmlparser] Strip ws and quotes on to_csv
When writing multiple values to csv make sure that whitespaces and carriage return linefeeds as well as quotation marks that have been added by the csv writer are removed before returning the csv string.
1 parent eed09df commit 9fa62d8

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

odml/tools/xmlparser.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@
2727

2828

2929
def to_csv(val):
30-
unicode_values = list(map(unicode, val))
30+
# Make sure all individual values do not contain
31+
# leading or trailing whitespaces.
32+
unicode_values = list(map(unicode.strip, map(unicode, val)))
3133
stream = StringIO()
3234
writer = csv.writer(stream, dialect="excel")
3335
writer.writerow(unicode_values)
34-
csv_string = stream.getvalue().strip()
36+
# Strip any csv.writer added carriage return line feeds
37+
# and double quotes before saving.
38+
csv_string = stream.getvalue().strip().strip('"')
3539
if len(unicode_values) > 1:
3640
csv_string = "[" + csv_string + "]"
3741
return csv_string

0 commit comments

Comments
 (0)