Fix #78: printing resulting bytes under python3

Binary outputs were printed as repr with b'abcde' instead as real bytes.
This commit is contained in:
Jan Vlcinsky
2018-04-13 22:33:53 +02:00
parent fd5f379e45
commit 598af0df4a
+14 -1
View File
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import os
from sys import stdout
from collections import OrderedDict
from contextlib import contextmanager
from inspect import isclass
@@ -523,7 +524,11 @@ Notes:
# Print results in desired format.
if format:
print(rows.export(format))
content = rows.export(format)
if isinstance(content, bytes):
print_bytes(content)
else:
print(content)
else:
print(rows.dataset)
except ImportError as impexc:
@@ -532,6 +537,14 @@ Notes:
print("Try to install missing packages.")
exit(60)
def print_bytes(content):
try:
stdout.buffer.write(content)
except AttributeError:
stdout.write(content)
# Run the CLI when executed directly.
if __name__ == '__main__':
cli()