我刚刚了解了pathlib,它应该使文件路径和位置不受操作系统的影响。 然而,当使用write file函数时,pathlib在windows“\”中添加了一个额外的反斜杠(尚未在基于POSIX的操作系统中进行测试),下面是代码
from pathlib import Path
path = Path("subDir/myFile")
print("file to write to is>>", path)
with path.open(mode='a') as outputlog:
outputlog.write('foo')
它给出以下输出
file to write to is>> subDir\myFile
FileNotFoundError: [Errno 2] No such file or directory: 'subDir\\myFile'
嗨,伙计们,感谢你的建议,父目录确实遗漏了这个修复首先创建目录的路径(没有文件名),然后
相关问题 更多 >
编程相关推荐