A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2011-December/114816.html below:

[Python-Dev] readd u'' literal support in 3.3?

[Python-Dev] readd u'' literal support in 3.3? [Python-Dev] readd u'' literal support in 3.3?"Martin v. Löwis" martin at v.loewis.de
Fri Dec 9 09:32:03 CET 2011
> Or, alternatively, you use 'six' (or a similar compatibility module)
> and ensure unicode at runtime, using native or binary strings
> otherwise:
> 
> ----------
> from six import u
> foo = u("this is a Unicode string in both Python 2.x and 3.x")
> bar = "this is an 8-bit string in Python 2.x and a Unicode string in 3.x"
> baz = b"this is an 8-bit string in Python 2.x and a bytes object in 3.x"
> ----------

An alternative here is to use a function for bar, not foo:

from __future__ import unicode_literals
from six.next import native_str
foo = "this is a Unicode string in both Python 2.x and 3.x"
bar = native_str("this is an 7-bit string in Python 2.x"
                 " and a Unicode string in 3.x")
baz = b"this is an 8-bit string in Python 2.x and a bytes object in 3.x"

Which of them is "better" depends on which of the two string types are
more common.

Regards,
Martin
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4