Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .py
- # encoding: utf-8
- name = 'helló wörld from two'
- # encoding: utf-8
- from __future__ import unicode_literals
- import two
- name = 'helló wörld from one'
- print name + two.name
- Traceback (most recent call last):
- File "one.py", line 5, in <module>
- print name + two.name
- UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 4: ordinal not in range(128)
- # encoding: utf-8
- html = '<html><body>helló wörld</body></html>'
- if isinstance(html, unicode):
- html = html.encode('utf-8')
- print 'DEBUG: %s' % html
- DEBUG: <html><body>helló wörld</body></html>
- # encoding: utf-8
- from __future__ import unicode_literals
- html = '<html><body>helló wörld</body></html>'
- if isinstance(html, unicode):
- html = html.encode('utf-8')
- print 'DEBUG: %s' % html
- Traceback (most recent call last):
- File "test.py", line 6, in <module>
- print 'DEBUG: %s' % html
- UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 16: ordinal not in range(128)
- >>> def foo(a=None): pass
- ...
- >>> foo(**{'a':1})
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- TypeError: foo() keywords must be strings
- # -*- coding: utf-8
- foo = "barré"
- unicode_literal
- from __future__ import unicode_literals
- bstr = b'xa4'
- assert eval(repr(bstr)) == bstr # fails in Python 2.7, holds in 3.1
- ustr = 'xa4'
- assert eval(repr(bstr)) == bstr # holds in Python 2.7 and 3.1
Add Comment
Please, Sign In to add comment