Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- s = "Byte string with national characters"
- us = u"Unicode string with national characters"
- data = unicode(random_byte_string)
- print(open("The full text of War and Peace.txt").read())
- > type t.py
- #encoding: cp1251
- s = "абвгд"
- us = u"абвгд"
- print repr(s), repr(us)
- > py -2 t.py
- 'xe0xe1xe2xe3xe4' u'u0430u0431u0432u0433u0434'
- <change encoding declaration in the file to cp866, do not change the contents>
- > py -2 t.py
- 'xe0xe1xe2xe3xe4' u'u0440u0441u0442u0443u0444'
- <transcode the file to utf-8, update declaration or replace with BOM>
- > py -2 t.py
- 'xd0xb0xd0xb1xd0xb2xd0xb3xd0xb4' u'u0430u0431u0432u0433u0434'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement