Bitbar: Python3 cant print unicode

Created on 24 Jul 2017  路  3Comments  路  Source: matryer/bitbar

Not quite sure the logistics behind this but attempting to print a string with Japanese characters (or anything utf-8/Unicode isn't working.

# Yes this string looks ugly, but just shows all of the things ive tried
print(str(u"銈偪銈儕")).encode('utf-8')

This throws a..

UnicodeEncodeError: `ascii` codec cant encode characters in positions 0-3: ordinal not in range

Any known fixes?

Most helpful comment

BitBar spawns a shell without locale variables. Python 3 inherits the shell encoding and in the absence of one, it defaults to ASCII. It will attempt to encode stdout in the default encoding before emission because.... reasons. The easiest thing to do is to prepend a UTF-8 locale inside the shebang:

#!/usr/bin/env LC_ALL=en_US.UTF-8 /usr/local/bin/python3

print('銈偪銈儕')

All 3 comments

Woops..

@jakeoid I suppose you can't convert unicode to ascii without being specific in python 3 -> str(u"銈偪銈儕") - maybe close this - it isn't a bitter bug in any case.

BitBar spawns a shell without locale variables. Python 3 inherits the shell encoding and in the absence of one, it defaults to ASCII. It will attempt to encode stdout in the default encoding before emission because.... reasons. The easiest thing to do is to prepend a UTF-8 locale inside the shebang:

#!/usr/bin/env LC_ALL=en_US.UTF-8 /usr/local/bin/python3

print('銈偪銈儕')
Was this page helpful?
0 / 5 - 0 ratings

Related issues

dzg picture dzg  路  4Comments

fenhl picture fenhl  路  4Comments

dbuezas picture dbuezas  路  7Comments

manojlds picture manojlds  路  11Comments

JayBrown picture JayBrown  路  8Comments