未知的 python 表达式 filename=r'/path/to/file' [英] Unknown python expression filename=r'/path/to/file'
问题描述
我发现这可能非常有用 python script,但遇到了这些我从未见过的表达式之前看过:
I found this potentially very useful python script, but came across these expressions which I've never seen before:
inputfilename = r'/path/to/infile'
outputfilename = r'/path/to/outfile'
我找不到搜索它的方法.r'...'
有什么作用?
I can't find a way to search for it. what does the r'...'
do?
感谢您的帮助!
推荐答案
r'..'
字符串修饰符导致 '..'
字符串被解释 <强>字面.这意味着, r'My\Path\Without\Escaping'
将计算为 'My\Path\Without\Escaping'
- 不会导致反斜杠转义字符.先验等效于 'My\\Path\\Without\\Escaping'
字符串,但没有原始修饰符.
The r'..'
string modifier causes the '..'
string to be interpreted literally. That means, r'My\Path\Without\Escaping'
will evaluate to 'My\Path\Without\Escaping'
- without causing the backslash to escape characters. The prior is equivalent to 'My\\Path\\Without\\Escaping'
string, but without the raw modifier.
注意:字符串不能以奇数个反斜杠结尾,即r'Bad\String\Example\'
不是正确的字符串.
Note: The string cannot end with an odd number of backslashes, i.e r'Bad\String\Example\'
is not a correct string.
这篇关于未知的 python 表达式 filename=r'/path/to/file'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!