python-2.x - 在 Python 中动态创建 u-strings
问题描述
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
解决方案
u 字符串在 Python 3 中不再存在。它们与普通字符串相同。所以只需使用普通字符串。
# Python 3
>>> u'Hello'
'Hello'
不要使用 Python 2,因为它不再受支持。如果您坚持使用 Python 2,请尝试:
# Python 2
>>> unicode('Hello')
u'Hello'
推荐阅读
- c# - cSharp asp net core entity framework web app-for each and added values
- php - 如何在 PHP 中显示 JSON 值的某些属性
- c++ - 避免在 boost::interprocess::managed_shared_memory 内部锁定
- javascript - 对 Int16Array 和 Array.Prototype.slice 中的元素进行操作后的值差异
- c++ - CMake 项目结构:何时在 target_sources 上使用 add_library/target_link_library?
- docker - windows 10 home + wsl的docker安装问题
- unity3d - Unity Shader Graph 上的颜色错误
- python - 如何创建参数接近给定参数的随机图?
- .net-core - httpcontext IdentityServer4 中有时不存在自定义声明
- google-colaboratory - 链接到 google colab 项目,以便学生必须复制和修改