【发布时间】:2021-08-18 16:27:36
【问题描述】:
我想在 windows 上写这段代码: os.path.join(folder1 + "/" + folder2)
它在 MAC 中运行良好,但在 Windows 中它给了我一个错误: OSError: [WinError 123] The filename, directory name, or volume label syntax is wrong: 'C:\Users\Khalaf\Desktop\test\dataset-图像\x.jpg' -> 'C:\Users\Khalaf\Desktop\test\dataset-images\C:\Users\Khalaf\Desktop\test\dataset-images-1.jpg'
【问题讨论】:
-
这能回答你的问题吗? Python os.path.join on Windows
-
你必须正确使用
os.path.join():os.path.join(folder1, folder2)。分隔符由函数添加。 -
我需要路径之间的“/”
-
您也可以使用
os.pathsep代替/。 -
在 Windows 上,您不“在路径之间需要 /”,因为 / 是 Windows 文件名中的非法字符。
os.path.join()知道,即使你不知道。