[英]How to replace encode('string_escape') when migrating code from py2 to py3
The 'string_escape' is removed from py3, and I can't find a way to replace the encode('string_escape') when migrating code from py2 to py3. 'string_escape' 已从 py3 中删除,当将代码从 py2 迁移到 py3 时,我找不到替换 encode('string_escape') 的方法。 Can someone help me?
有人能帮我吗?
My code in py2:我在py2中的代码:
a = '["\\\"\\\""]'
print(a.encode('string_escape'))
Expected output:预期 output:
["\\"\\""]
What should I do in py3?我应该在py3中做什么?
Thanks @Jan Wilamowski.谢谢@Jan Wilamowski。 Got the answer.
得到了答案。
>>> a = '["\\\"\\\""]'
>>> print(a.encode('unicode_escape').decode('utf-8'))
["\\"\\""]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.