转义字符改变Python中字符串的内容

发布于 2025-01-20 16:41:17 字数 449 浏览 0 评论 0原文

我将此文件路径保存到一个变量上,因此

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

第几種人 2025-01-27 16:41:17

使用原始字符串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")

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文