我需要确定一些powershell路径字符串在Python中的交叉位置。你知道吗
如何检测Python中的路径是否以.\
开头??你知道吗
举个例子:
import re
file_path = ".\reports\dsReports"
if re.match(r'.\\', file_path):
print "Pass"
else:
print "Fail"
在它列出的调试器中,此操作失败
expression = .\\\\\\
string = .\\reports\\\\dsReports
如果我尝试这样使用replace:
import re
file_path = ".\reports\dsReports"
testThis = file_path.replace(r'\', '&jkl$ff88')
if re.match(r'.&jkl$ff88', file_path):
print "Pass"
else:
print "Fail"
testThis
变量的结果如下:
testThis = '.\\reports&jkl$ff88dsReports'
相当大胆。你知道吗
发生这种情况的原因是
\r
是一个转义序列。您需要通过将反斜杠加倍来转义反斜杠,或者使用如下原始字符串文字:然后检查是否以
".\\"
开头:相关问题 更多 >
编程相关推荐