31
31
__version__ = "0.7.3"
32
32
33
33
34
+ MIN_PADDING = 2
35
+
36
+
34
37
Line = namedtuple ("Line" , ["begin" , "hline" , "sep" , "end" ])
35
38
36
39
@@ -764,7 +767,8 @@ def tabulate(tabular_data, headers=[], tablefmt="simple",
764
767
\\ end{tabular}
765
768
766
769
"""
767
-
770
+ if tabular_data is None :
771
+ tabular_data = []
768
772
list_of_lists , headers = _normalize_tabular_data (tabular_data , headers )
769
773
770
774
# optimization: look for ANSI control codes once,
@@ -785,15 +789,17 @@ def tabulate(tabular_data, headers=[], tablefmt="simple",
785
789
786
790
# align columns
787
791
aligns = [numalign if ct in [int ,float ] else stralign for ct in coltypes ]
788
- minwidths = [width_fn (h )+ 2 for h in headers ] if headers else [0 ]* len (cols )
792
+ minwidths = [width_fn (h ) + MIN_PADDING for h in headers ] if headers else [0 ]* len (cols )
789
793
cols = [_align_column (c , a , minw , has_invisible )
790
794
for c , a , minw in zip (cols , aligns , minwidths )]
791
795
792
796
if headers :
793
797
# align headers and add headers
794
- minwidths = [max (minw , width_fn (c [0 ])) for minw , c in zip (minwidths , cols )]
798
+ t_cols = cols or [['' ]] * len (headers )
799
+ t_aligns = aligns or [stralign ] * len (headers )
800
+ minwidths = [max (minw , width_fn (c [0 ])) for minw , c in zip (minwidths , t_cols )]
795
801
headers = [_align_header (h , a , minw )
796
- for h , a , minw in zip (headers , aligns , minwidths )]
802
+ for h , a , minw in zip (headers , t_aligns , minwidths )]
797
803
rows = list (zip (* cols ))
798
804
else :
799
805
minwidths = [width_fn (c [0 ]) for c in cols ]
0 commit comments