mirror of
https://github.com/kennethreitz/records.git
synced 2026-06-05 06:46:17 +00:00
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:
+14
-1
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user