python路径反斜杠替换,修改文件后缀名

文件路径中反斜杠替换和文件后缀名修改

文件路径和名称:
xlsPath=D:\Python\files\文件.pdf
xlsPath = (filePath[:-3] + "xls")
print(xlsPath)
D:\Python\files\文件.xls

路径中的反斜杠替换
xlsPath=D:/Python/files/文件.xls
xlsPath=xlsPath.replace('\\', "/")
print(xlsPath)
D:/Python/files/文件.xls

猜你喜欢

转载自blog.csdn.net/tone1128/article/details/105538536