[英]Python: FileNotFoundError: [Errno 2] No such file or directory error
Want to name a file with open function, but error occur.想用打开的 function 命名文件,但出现错误。 Can not figure out what is the problem, with just img_name = 'image1' everything is OK.
无法弄清楚是什么问题,只需 img_name = 'image1' 一切正常。 Thanks
谢谢
img_name = f'{id_}/image-{img_num}.jpg'
with open(img_name, 'wb') as img_file:
When writing a file in python, the folder you write to (here {id_}
) must exist.在 python 中写入文件时,您写入的文件夹(此处为
{id_}
)必须存在。
You can use os.makedirs(folder)
if it doesn't currently exist.如果当前不存在,您可以使用
os.makedirs(folder)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.