Guest User

Untitled

a guest
Jun 20th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. .py
  2.  
  3. # encoding: utf-8
  4. name = 'helló wörld from two'
  5.  
  6. # encoding: utf-8
  7. from __future__ import unicode_literals
  8. import two
  9. name = 'helló wörld from one'
  10. print name + two.name
  11.  
  12. Traceback (most recent call last):
  13. File "one.py", line 5, in <module>
  14. print name + two.name
  15. UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 4: ordinal not in range(128)
  16.  
  17. # encoding: utf-8
  18. html = '<html><body>helló wörld</body></html>'
  19. if isinstance(html, unicode):
  20. html = html.encode('utf-8')
  21. print 'DEBUG: %s' % html
  22.  
  23. DEBUG: <html><body>helló wörld</body></html>
  24.  
  25. # encoding: utf-8
  26. from __future__ import unicode_literals
  27. html = '<html><body>helló wörld</body></html>'
  28. if isinstance(html, unicode):
  29. html = html.encode('utf-8')
  30. print 'DEBUG: %s' % html
  31.  
  32. Traceback (most recent call last):
  33. File "test.py", line 6, in <module>
  34. print 'DEBUG: %s' % html
  35. UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 16: ordinal not in range(128)
  36.  
  37. >>> def foo(a=None): pass
  38. ...
  39. >>> foo(**{'a':1})
  40. Traceback (most recent call last):
  41. File "<stdin>", line 1, in <module>
  42. TypeError: foo() keywords must be strings
  43.  
  44. # -*- coding: utf-8
  45.  
  46. foo = "barré"
  47.  
  48. unicode_literal
  49.  
  50. from __future__ import unicode_literals
  51.  
  52. bstr = b'xa4'
  53. assert eval(repr(bstr)) == bstr # fails in Python 2.7, holds in 3.1
  54.  
  55. ustr = 'xa4'
  56. assert eval(repr(bstr)) == bstr # holds in Python 2.7 and 3.1
Add Comment
Please, Sign In to add comment