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/2017-May/147949.html below:

[Python-Dev] Format strings, Unicode, and Py2.7: need clarification

[Python-Dev] Format strings, Unicode, and Py2.7: need clarificationCraig Rodrigues rodrigc at crodrigues.org
Wed May 17 17:41:29 EDT 2017
Hi,

While cleaning up some code during Python 2 -> Python 3 porting,
I switched some code to use str.format(), I found this behavor:

Python 2.7
=========
a = "%s" % "hi"
b = "%s" % u"hi"
c = u"%s" % "hi"
d = "{}".format("hi")
e = "{}".format(u"hi")
f = u"{}".format("hi")

type(a) == str
type(b) == unicode
type(c) == unicode
type(d) == str
type(e) == str
type(f) == unicode

My intuition would lead me to believe that type(b)
and type(e) would be the same (unicode), but they are not.
The confusion for me is why is type(e) of type str, and not unicode?

Can someone clarify this for me?

I understand that in Python 3, all these cases are str, so it is not
as big a problem there, but I am trying to keep things working on
Python 2.7.

Thanks.
--
Craig
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20170517/383b0176/attachment.html>
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