Can't print Unicode Bitcoin symbol in Python 2 -
i trying print unicode bitcoin symbol \u2043 in python 2. have tried adding #-*- coding: utf-8 -*-.
$ python2 -c 'print u'\u0243'' raises unicodeencodeerror: 'ascii' codec can't encode character u'\u0243' in position 0: ordinal not in range(128). however, doing python shell works.
$ python2 >>> print u'\u0243' Ƀ why isn't code working?
bitcoin = u'\u0243' quote = u'{:,.2f}'.format(float(val), '.2f') print bitcoin, quote
on unix, if sys.stdout.isatty() returns true sys.stdout.encoding 'ansi_x3.4-1968' (ascii) should configure locale (check lang, lc_ctype, lc_all envvars) use non-ascii encoding if need print non-ascii characters.
if sys.stdout.isatty() false configure pythonioencoding envvar outside script.
print unicode, don't hardcode character encoding of environment inside script.
Comments
Post a Comment