Fix Python 2 Unicode Problem

When piping to stdout the special handling for Pthon 3 will cause
problems in Python 2 and produce an Unicode encoding error. This commit
separates the output handling of both Python versions.

Signed-off-by: Lars Kiesow <lkiesow@uos.de>
This commit is contained in:
Lars Kiesow 2016-01-01 19:31:00 +01:00
parent 5caebc220c
commit 9b6e3cb45e
No known key found for this signature in database
GPG key ID: 5DAFE8D9C823CE73

View file

@ -15,7 +15,10 @@ def print_enc(s):
'''Print function compatible with both python2 and python3 accepting strings
and byte arrays.
'''
print(s.decode('utf-8') if type(s) == type(b'') else s)
if sys.version_info[0] >= 3:
print(s.decode('utf-8') if type(s) == type(b'') else s)
else:
print(s)