Changes between Version 11 and Version 12 of PortingNotesFor2To3


Ignore:
Timestamp:
12/26/2011 06:22:09 AM (3 years ago)
Author:
vsajip
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • PortingNotesFor2To3

    v11 v12  
    1212  replace `u'foo'` with `u('foo')` and `b'bar'` with `b('bar')` throughout the source.
    1313  The same applies to the constants with double quotes (`u"foo"` or `b"bar"`, which should be replaced by
    14   `u("foo")` or `b("bar")` respectively). '''Note:''' this is needed for Python 2.5 compatibility only. For compatibility only with Python 2.6 and later, add `from __future__ import unicode_literals` in all modules where you are using Unicode literals, and remove the `u` prefix from the Unicode literals, as you don't need it. If you need native strings, use `from django.utils.py3 import n` and replace those literals with `n(...)`. This will return `str` on both 2.x and 3.x. If you need byte strings, use `b'foo'`.
     14  `u("foo")` or `b("bar")` respectively). '''Note:''' this is needed for Python 2.5 compatibility only. For compatibility only with Python 2.6 and later, add `from __future__ import unicode_literals` in all modules where you are using Unicode literals, and remove the `u` prefix from the Unicode literals, as you don't need it. If you need native strings, use `from django.utils.py3 import n` and replace those literals with `n(...)`. This will return `str` on both 2.x and 3.x. If you need byte strings, use `b'foo'`. Unfortunately, it's hard to know where native strings are required: for example, some 2.x C-based APIs expect native strings and behave unexpectedly when passed Unicode strings.
    1515
    1616* If you need to make any code conditional on 2.x vs. 3.x, you can do `from django.utils.py3 import PY3` and use `PY3`
Back to Top