Skip to content

Instantly share code, notes, and snippets.

@cocodrips
Created March 20, 2014 10:01
Show Gist options
  • Save cocodrips/9660640 to your computer and use it in GitHub Desktop.
Save cocodrips/9660640 to your computer and use it in GitHub Desktop.
unicode/ str
# -*- 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