example:
print(tabulate([["你好".encode("utf-8"), "你好"]], headers=["bytes", "str"]))
Currently, an UnicodeDecodeError will be raised:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128)
Related code is here:
As I understand it, an UnicodeDecodeError should be caught instead of a TypeError, right?
So output would be like:
bytes str
--------------------------- -----
b'\xe4\xbd\xa0\xe5\xa5\xbd' 你好
I'm not sure if it's the designed behavior, but i think it's a proper way to handle non-ascii bytes.
Furthermore, why not return all bytes as str(val) directly without trying to return str(val, "ascii") at first? If the caller want to print decoded value, they can decode it explicitly before calling tabulate().
example:
Currently, an UnicodeDecodeError will be raised:
Related code is here:
python-tabulate/tabulate.py
Line 1070 in 3f0757e
As I understand it, an UnicodeDecodeError should be caught instead of a TypeError, right?
So output would be like:
I'm not sure if it's the designed behavior, but i think it's a proper way to handle non-ascii bytes.
Furthermore, why not return all bytes as str(val) directly without trying to return str(val, "ascii") at first? If the caller want to print decoded value, they can decode it explicitly before calling tabulate().