Created
March 20, 2014 10:01
-
-
Save cocodrips/9660640 to your computer and use it in GitHub Desktop.
unicode/ str
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
# -*- coding: utf-8 -*- | |
uj = u'こんにちは' | |
ue = u'Hello' | |
sj = 'こんにちは' | |
se = 'Hello' | |
print ue == se # True | |
print uj == sj # False Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal | |
print sj.decode('utf-8'), type(sj.decode('utf-8')) #こんにちは | |
print unicode(sj, 'utf-8'), type(unicode(sj, 'utf-8')) #こんにちは 上と同じ | |
print sj.decode() # UnicodeDecodeError: 'ascii' codec can't decode byte 0xe3 in position 0: ordinal not in range(128) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment