$ locale
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
$ ./test.sh
python sad.py
UTF-8
Привет Я unicode символ - ♡♢♚♛ ඓඍඏ
python happy.py
before: UTF-8
after: UTF-8
Привет Я unicode символ - ♡♢♚♛ ඓඍඏ
python sad.py | cat
Traceback (most recent call last):
File "sad.py", line 6, in <module>
None
print u'Привет Я unicode символ - ♡♢♚♛ ඓඍඏ'
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-5: ordinal not in range(128)
python happy.py | cat
before: None
after: None
Привет Я unicode символ - ♡♢♚♛ ඓඍඏ
Last active
December 10, 2015 13:55
-
-
Save maizy/b9550d39c54d71ebc4f5 to your computer and use it in GitHub Desktop.
python cli encoding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
import sys | |
print 'before: {}'.format(sys.stdout.encoding) | |
reload(sys) | |
sys.setdefaultencoding('utf-8') | |
print 'after: {}'.format(sys.stdout.encoding) | |
print u'Привет Я unicode символ - ♡♢♚♛ ඓඍඏ' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
import sys | |
print sys.stdout.encoding | |
print u'Привет Я unicode символ - ♡♢♚♛ ඓඍඏ' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "python sad.py" | |
python sad.py | |
echo -e "\n\n\n" | |
echo "python happy.py" | |
python happy.py | |
echo -e "\n\n\n" | |
echo "python sad.py | cat" | |
python sad.py | cat | |
echo -e "\n\n\n" | |
echo "python happy.py | cat" | |
python happy.py | cat | |
echo -e "\n\n\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment