我从 XML 读取路径列表,路径包含不规则元素使用 通过某个在内部翻译它们的应用程序。 当前路径字符串对我来说没有用,我希望将它们标准化。
example:
path = "%personal%\new_lcation\%vendorlibs%\generated"
# split this to a list
omponents = path.split(os.sep)
# replace elemnts 0,2
components[0]="c:\ProgramFiles"
components[2]="somthing"
如何将现在的所有内容连接到标准路径字符串?
谢谢
最佳答案
os.path.join(*组件)
。 os.path.join
documentation .
关于python - 从分割的路径字符串构建新的路径字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11180337/