gpt4 book ai didi

javascript - 模仿 Javascript escape() 函数

转载 作者:行者123 更新时间:2023-11-30 15:21:17 25 4
gpt4 key购买 nike

如本表所示http://www.javascripter.net/faq/accentedcharacters.htm , escape()encodeURI() 是有区别的。

我需要模仿 escape() 的行为,因为另一个系统需要它,但事实证明这对 Python 来说很复杂。

msg = "¿El mañana exitirá?"

# javascript: console.log(escape(msg)) # %BFEl%20ma%F1ana%20exitir%E1%3F
q = urllib.parse.quote(msg)
print(q) # %C2%BFEl%20ma%C3%B1ana%20exitir%C3%A1%3F

q = urllib.parse.quote(msg, encoding="unicode_escape")
print(q) # %5CxbfEl%20ma%5Cxf1ana%20exitir%5Cxe1%3F

如何让 Python 模仿 escape

最佳答案

事实证明,我非常接近:

msg = "¿El mañana exitirá?"
q = urllib.parse.quote(msg, encoding="raw_unicode_escape")
print(q) # %BFEl%20ma%F1ana%20exitir%E1%3F

关于javascript - 模仿 Javascript escape() 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43694242/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com