今天遇到一个问题,在集成的环境中是Linux,本地开发是Windows,在帮助文档的编写中,路径超链接表达有问题,写了一个小函数解决这个问题,
def windows_to_linux(windowsPath):
windowsPath_h = windowsPath.split(':')[1] #将windows中以:分割成两个部分
windowsPath_w = windowsPath_h.split("\\")#将后面部分以\\分割,会得到一个列表
del windowsPath_w[0]#删除第一个元素
linuxPath1 = "/".join(windowsPath_w)#以/连接
hh = windowsPath.split(':')[0]#用一个变量接受头部
hh = '/' + hh + "/" #在头部前后各加一个/
linuxPath = hh + linuxPath1
print(linuxPath)
输入:
w1 = "D:\whyuandashuai\syslab-docs\sys\projects\Help\Doc\Tydashuai\Regression\partialDependence_py.md"
windows_to_linux(w1)
输出:
/D/whyuandashuai/syslab-docs/sys/projects/Help/Doc/Tydashuai/Regression/partialDependence_py.md
大功告成。
觉得有用的道友自行取用!
2022.11.23_悍马提缰