Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. s = "Byte string with national characters"
  2. us = u"Unicode string with national characters"
  3.  
  4. data = unicode(random_byte_string)
  5.  
  6. print(open("The full text of War and Peace.txt").read())
  7.  
  8. > type t.py
  9. #encoding: cp1251
  10. s = "абвгд"
  11. us = u"абвгд"
  12. print repr(s), repr(us)
  13. > py -2 t.py
  14. 'xe0xe1xe2xe3xe4' u'u0430u0431u0432u0433u0434'
  15.  
  16. <change encoding declaration in the file to cp866, do not change the contents>
  17. > py -2 t.py
  18. 'xe0xe1xe2xe3xe4' u'u0440u0441u0442u0443u0444'
  19.  
  20. <transcode the file to utf-8, update declaration or replace with BOM>
  21. > py -2 t.py
  22. 'xd0xb0xd0xb1xd0xb2xd0xb3xd0xb4' u'u0430u0431u0432u0433u0434'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement