Created
April 11, 2012 22:43
-
-
Save mibe/2363259 to your computer and use it in GitHub Desktop.
test
This file contains 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 | |
# -*- coding: utf-8 -*- | |
import sys | |
values = {} | |
values["without_u"] = "Fertőboz" | |
values["with_u"] = u"Fertőboz" | |
print "my output encoding: ", sys.stdout.encoding | |
print values | |
print "without_u is unicode? ", isinstance(values["without_u"], unicode) | |
print "without_u is str? ", isinstance(values["without_u"], str) | |
print "with_u is unicode? ", isinstance(values["with_u"], unicode) | |
print "with_u is str? ", isinstance(values["with_u"], str) | |
print values["without_u"] | |
print values["with_u"] |
This file contains 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
my output encoding: UTF-8 | |
{'without_u': 'Fert\xc5\x91boz', 'with_u': u'Fert\u0151boz'} | |
without_u is unicode? False | |
without_u is str? True | |
with_u is unicode? True | |
with_u is str? False | |
Fertőboz | |
Fertőboz |
This file contains 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
my output encoding: cp850 | |
{'without_u': 'Fert\xc5\x91boz', 'with_u': u'Fert\u0151boz'} | |
without_u is unicode? False | |
without_u is str? True | |
with_u is unicode? True | |
with_u is str? False | |
Fertőboz | |
Traceback (most recent call last): | |
File "C:\Dokumente und Einstellungen\Michi\Desktop\test.py", line 16, in <modu | |
le> | |
print values["with_u"] | |
File "C:\Programme\Python27\lib\encodings\cp850.py", line 12, in encode | |
return codecs.charmap_encode(input,errors,encoding_map) | |
UnicodeEncodeError: 'charmap' codec can't encode character u'\u0151' in position | |
4: character maps to <undefined> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment