Skip to content

Commit 55b28be

Browse files
committed
[#171] Fix for python 2.7
1 parent f70c414 commit 55b28be

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

flattentool/input.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,19 @@ def generate_rows(self, dictreader, sheet_name):
498498
skip_rows = sheet_configuration.get("skipRows", 0)
499499
header_rows = sheet_configuration.get("headerRows", 1)
500500
for i in range(0, configuration_line + skip_rows):
501-
next(dictreader.reader)
502-
fieldnames = dictreader.fieldnames
501+
previous_row = next(dictreader.reader)
502+
if sys.version > '3': # If Python 3 or greater
503+
fieldnames = dictreader.fieldnames
504+
else:
505+
# unicodecsv dictreader always reads the headingline first
506+
# so in the case of there being any rows to skip look at
507+
# previous row and use that for fieldnames.
508+
if (configuration_line + skip_rows):
509+
fieldnames = previous_row
510+
dictreader.fieldnames = fieldnames
511+
dictreader.unicode_fieldnames = fieldnames
512+
else:
513+
fieldnames = dictreader.unicode_fieldnames
503514
for i in range(0, header_rows - 1):
504515
next(dictreader.reader)
505516
for line in dictreader:

0 commit comments

Comments
 (0)