假你想写一个文件filename='/root/wujin/5.2/03.html'但是文件夹可能不存在。先这样子targetpath = os.path.dirname(filename)if not os.path.isdir(targetpath): os.makedirs(targetpath)然后你就可以打到filename,写入内容了。
麻烦吧python抛出来的异常贴出来才能知道具体原因。