python - 未知的 python 表达式 filename=r'/path/to/file'

标签 python string

我发现这个可能非常有用的 python script , 但遇到了我以前从未见过的这些表达式:

inputfilename = r'/path/to/infile'
outputfilename = r'/path/to/outfile'

我找不到搜索它的方法。 r'...' 做什么?

感谢您的帮助!

最佳答案

r'..' 字符串修饰符导致 '..' 字符串被解释为字面意义。这意味着,r'My\Path\Without\Escaping' 将评估为 'My\Path\Without\Escaping' - 不会导致反斜杠转义字符。先验等效于 'My\\Path\\Without\\Escaping' 字符串,但没有原始修饰符。

注意:字符串不能以奇数个反斜杠结尾,即r'Bad\String\Example\'不是正确的字符串。

关于python - 未知的 python 表达式 filename=r'/path/to/file',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19034822/

相关文章:

Python执行命令行,发送输入和读取输出

python - 如何解码 dtype=numpy.string_ 的 numpy 数组?

c - C中用另一个子字符串替换部分字符串

.net - 为什么 regex.IsMatch(str) 比 str.EndsWith(不变文化)快?

c - 字符串正在打印奇怪的字符 - lex 中的 c 代码

c - 如何在方法中复制字符串?

Python:附加到存储在搁置字典中的实例所拥有的列表

python - Bokeh 未使用所有可用空间

python如何仅使用一个函数从列表中形成最大可能的数字

python - python dict str() 函数是否可靠地对键进行排序?