Revision: d523341cc978
Branch: default
Author: "Hans Petter Langtangen <
h...@simula.no>"
Date: Sun Jun 16 22:16:28 2013
Log: Fixed bug in analysis of csv table with varying no of columns.
http://code.google.com/p/doconce/source/detail?r=d523341cc978
Modified:
/lib/doconce/common.py
/lib/doconce/misc.py
=======================================
--- /lib/doconce/common.py Sun May 5 07:00:29 2013
+++ /lib/doconce/common.py Sun Jun 16 22:16:28 2013
@@ -91,11 +91,26 @@
def table_analysis(table):
"""Return max width of each column."""
+ # Find max no of columns
+ max_num_columns = 0
+ for row in table:
+ max_num_columns = max(max_num_columns, len(row))
+ # Consistency checks
+ if table[0] != ['horizontal rule'] or \
+ table[2] != ['horizontal rule'] or \
+ table[-1] != ['horizontal rule']:
+ print '*** error: table lacks the right three horizontal rules'
+ if len(table[1]) < max_num_columns:
+ print '*** warning: table headline with entries'
+ print ' ', '| ' + ' | '.join(table[1]) + ' |'
+ print ' has %d columns while further down there are %d
columns' % \
+ (len(table[1]), max_num_columns)
+ # Find width of the various columns
column_list = []
for i, row in enumerate(table):
if row != ['horizontal rule']:
if not column_list:
- column_list = [[]]*len(row)
+ column_list = [[]]*max_num_columns
for j, column in enumerate(row):
column_list[j].append(len(column))
return [max(c) for c in column_list]
=======================================
--- /lib/doconce/misc.py Sun Jun 9 01:03:20 2013
+++ /lib/doconce/misc.py Sun Jun 16 22:16:28 2013
@@ -5928,7 +5928,8 @@
csvfile = open(filename, 'r')
table = []
for row in csv.reader(csvfile):
- table.append(row)
+ if row:
+ table.append(row)
csvfile.close()
# Now, table is list of lists
for i in range(len(table)):
@@ -6185,4 +6186,3 @@
old_files.append(old_filename)
print 'doconce diff', old_filename, filename
#pydiff(filenames, old_files)
-