转义字符改变Python中字符串的内容
我将此文件路径保存到一个变量上,因此
path = "\\10.24.161.21\TVC-NL-Internal2\CPL\90_DAY\01_RUSHES\20210923\210923_90DF_FX9_LR_A001\XDROOT\Clip\A0002.MXF"
当我打印时,我会得到
'\\10.24.161.21\\TVC-NL-Internal2\\CPL\\90_DAY\x01_RUSHES\x8210923\x88923_90DF_FX9_LR_A001\\XDROOT\\Clip\\A0002.MXF'
一些文件夹名称的开始,而后斜切正在更改。
我如何避免这种情况?
编辑: 谢谢。我可以用作原始字符串的硬码。但是我正在从文本文件中解析很多字符串,然后将它们存储在列表中。我如何将所有这些变成原始字符串?
I have this file path saved to a variable like so
path = "\\10.24.161.21\TVC-NL-Internal2\CPL\90_DAY\01_RUSHES\20210923\210923_90DF_FX9_LR_A001\XDROOT\Clip\A0002.MXF"
when I print I get this
'\\10.24.161.21\\TVC-NL-Internal2\\CPL\\90_DAY\x01_RUSHES\x8210923\x88923_90DF_FX9_LR_A001\\XDROOT\\Clip\\A0002.MXF'
the beginnings of some folder names are being altered by the backslash.
How do I avoid this?
Edit:
Thanks. I can hard code as raw strings. But I'm parsing a lot of strings from a text file and storing them in a list. How do I turn all of those into raw strings?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用原始字符串r忽略python中的逃生序列
例如
打印(r“ C:\ 10.24.56 \用户”)
Use the raw string r to ignore the escape sequence in python
For example
Print(r"c:\10.24.56\users")