Apparently, when running as a script, sys.stdout might not have an encoding

svn: r23374
This commit is contained in:
Doug Blank 2013-10-23 17:03:40 +00:00
parent bcf43e9a02
commit 46ceab3ca8

View File

@ -415,7 +415,10 @@ class GrampsLocale(object):
#Ensure that output is encoded correctly to stdout and stderr. This is #Ensure that output is encoded correctly to stdout and stderr. This is
#much less cumbersome and error-prone than encoding individual outputs #much less cumbersome and error-prone than encoding individual outputs
#and better handles the differences between Python 2 and Python 3: #and better handles the differences between Python 2 and Python 3:
_encoding = sys.stdout.encoding or sys.getdefaultencoding() try:
_encoding = sys.stdout.encoding or sys.getdefaultencoding()
except:
_encoding = "UTF-8"
if sys.version_info[0] < 3: if sys.version_info[0] < 3:
sys.stdout = codecs.getwriter(_encoding)(sys.stdout, sys.stdout = codecs.getwriter(_encoding)(sys.stdout,
'backslashreplace') 'backslashreplace')