Skip to content

Instantly share code, notes, and snippets.

@mibe
Created April 11, 2012 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mibe/2363259 to your computer and use it in GitHub Desktop.
Save mibe/2363259 to your computer and use it in GitHub Desktop.
test
#!/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"]
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
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