From 9b6e3cb45ec111d0c1293d7c943435343c182974 Mon Sep 17 00:00:00 2001 From: Lars Kiesow Date: Fri, 1 Jan 2016 19:31:00 +0100 Subject: [PATCH] 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 --- feedgen/__main__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/feedgen/__main__.py b/feedgen/__main__.py index 24fd463..4463ea6 100644 --- a/feedgen/__main__.py +++ b/feedgen/__main__.py @@ -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)