# coding: utf-8 __author__ = 'yoder' # If you get an error like the one below, you need # to set (In PyCharm settings) # Editor->File Encodings->Project Encoding # to UTF-8 # # print u'Thing:\u33AA:' # Traceback (most recent call last): # File "D:/Dropbox/PyCharm16q1/cs2910_prep/class8_1_Unicode/unicode_fun.py", line 4, in # print u'Thing:\u33AA:' # File "C:\Python27\lib\encodings\cp1252.py", line 12, in encode # return codecs.charmap_encode(input,errors,encoding_table) # UnicodeEncodeError: 'charmap' codec can't encode character u'\u33aa' in position 6: character maps to s = u'A:☯' for c in s: print "{:04x}".format(ord(c)) for c in s.encode('utf-8'): print "{:02x}".format(ord(c))+": "+c with open("unicode.txt", "w") as text_file: text_file.write(s.encode('utf-8')) print s