From 33d02461bb43b65de8ef5f5c2978d9fb8ff52628 Mon Sep 17 00:00:00 2001 From: Niru Maheswaranathan Date: Mon, 2 May 2016 14:20:15 -0700 Subject: [PATCH] Better python2 compatibility (six.string_types) --- requirements.txt | 1 + tableprint.py | 18 +++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/requirements.txt b/requirements.txt index 24ce15a..bc2cbbd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ numpy +six diff --git a/tableprint.py b/tableprint.py index b42d97b..4b9d45a 100644 --- a/tableprint.py +++ b/tableprint.py @@ -3,18 +3,18 @@ Tableprint A module to print and display ASCII formatted tables of data +Usage +----- +>>> data = np.random.randn(10,3) +>>> headers = ['Column A', 'Column B', 'Column C'] +>>> tableprint.table(data, headers) """ - from __future__ import print_function -try: - import numpy as np -except ImportError: - pass +from six import string_types +import numpy as np -# exports __all__ = ['table', 'row', 'header', 'hr', 'humantime', 'frame'] - -__version__ = '0.1.9' +__version__ = '0.2.0' def table(data, headers, format_spec='5g', column_width=10, outer_char='|', corner_char='+', line_char='-'): @@ -138,7 +138,7 @@ def row(values, column_width=10, format_spec='5g', outer_char='|'): # unpack d, prec = val - if isinstance(d, str): + if isinstance(d, string_types): return ('{:>%i}' % column_width).format(d) elif isinstance(d, (int, float, np.integer, np.float)):