【发布时间】:2021-05-20 19:25:12
【问题描述】:
https://docs.python.org/2/tutorial/introduction.html#unicode-strings
我目前正在尝试弄清楚如何动态创建 u-strings(例如,以 u'helloWorld' 的形式)。如果可能的话,我想创建一个带有字符串连接或字符串注入的 u-string,以使用变量动态创建一个新的 u-string,例如 u'{variableName}'。有没有办法做到这一点?
Python 2 u-strings 的使用是为了使用 gcloud 函数,我试图在其中动态添加文档。该文档使用 u-strings,可以在以下位置找到:
https://firebase.google.com/docs/firestore/manage-data/add-data
【问题讨论】:
-
字符串与 unicode 字符串仅在 Python 2 中有意义,而 Python 2 在 2021 年很少有意义。您想要完成什么? (公平地说,Apple 将 Python 2 设为默认值太久了,这让事情变得更加混乱。
-
你真的在使用 Python 2 吗?在 Python 3 中,所有字符串都是 Unicode。它们的管理方式与常规字符串一样。
-
你为什么要编写 Python 2 教程?
-
您尝试过哪些不起作用的方法?
mys = u"one" + u"two"在 Python 2 中应该可以正常工作。 -
Python 2 达到了它的end of life on January 1, 2020。如果我没记错的话,所有字符串都是u-strings by default in Python 3。
标签: python-2.x