简体   繁体   English

反斜杠和\\ xnnn转换为ascii

[英]backslash and \xnnn conversion to ascii

I am reading from a file the path for some jpg files and the format is: 我正在从文件中读取一些jpg文件的路径,其格式为:

...
prc103\CV137\2018\09\14\21\103137435939720180914210353_F01.jpg
prc103\CV137\2018\09\14\21\103137435940120180914210820_F01.jpg
prc103\CV137\2018\09\14\21\103137435946020180914215915_F01.jpg
...

I want to change some characteristics of this path but when I try to manipulate the string I have no success because it changed to this: 我想更改此路径的某些特征,但是当我尝试操作字符串时,我没有成功,因为它更改为:

'prc103\\CV137\x818\x009\x0c\x11C137435939720180914210353_F01.jpg'

How to have the original clean ascii string ? 如何拥有原始的干净ascii字符串?

From the documentation on "Lexical analysis" : 从有关“词法分析”的文档中:

The backslash () character is used to escape characters that otherwise have a special meaning, such as newline, backslash itself, or the quote character. 反斜杠()字符用于转义具有特殊含义的字符,例如换行符,反斜杠本身或引号字符。

You can find more examples of such "escape sequences" in the documentation or see for yourself by opening a Python shell (ie typing in \\2018 , which will return \\x818 , as in your example). 您可以在文档中找到此类“转义序列”的更多示例,也可以通过打开Python Shell来自己查看(即键入\\2018 ,如您的示例所示,该命令将返回\\x818 )。

Is the file you're reading accessible to you? 您正在阅读的文件可以访问吗? Try to find and replace the backslashes in your text file with forward slashes. 尝试查找文本文件中的反斜杠并将其替换为正斜杠。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM