【发布时间】:2017-03-31 21:13:35
【问题描述】:
如何从 python3 字符串对象创建 unicode 实体?
有smt _ 1 #,我想生成smt%20_%201%20%23
【问题讨论】:
标签: python python-3.x unicode python-unicode
如何从 python3 字符串对象创建 unicode 实体?
有smt _ 1 #,我想生成smt%20_%201%20%23
【问题讨论】:
标签: python python-3.x unicode python-unicode
使用来自urllib.parse 的quote:
>>> from urrlib.parse import quote
>>> quote('smt _ 1 #')
'smt%20_%201%20%23'
由于您不是在处理 url,因此您似乎不需要指定任何安全字符。如果您还需要转义/,请将safe='' 传递给quote。
【讨论】: