Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:FileNotFoundError:[Errno 2]没有这样的文件或目录:_Python - Fatal编程技术网

Python:FileNotFoundError:[Errno 2]没有这样的文件或目录:

Python:FileNotFoundError:[Errno 2]没有这样的文件或目录:,python,Python,我正在使用docxtpl和format函数生成多个word文档,但收到以下错误消息: Traceback (most recent call last): File "D:\Final report Card\Final Report Card.py", line 68, in <module> tpl.save("./final Report Cards/{}_Final Report Cards.docx".format(file_name

我正在使用docxtpl和format函数生成多个word文档,但收到以下错误消息:

Traceback (most recent call last):
File "D:\Final report Card\Final Report Card.py", line 68, in <module>
tpl.save("./final Report Cards/{}_Final Report Cards.docx".format(file_name))
File "C:\Users\AppData\Roaming\Python\Python39\site-packages\docxtpl\__init__.py", line 632, in save self.docx.save(filename, *args, **kwargs)
File "C:\Users\AppData\Roaming\Python\Python39\site-packages\docx\document.py", line 135, in save self._part.save(path_or_stream)
File "C:\Users\AppData\Roaming\Python\Python39\site-packages\docx\parts\document.py", line 111, in save self.package.save(path_or_stream)
File "C:\Users\AppData\Roaming\Python\Python39\site-packages\docx\opc\package.py", line 172, in save PackageWriter.write(pkg_file, self.rels, self.parts)
File "C:\Users\AppData\Roaming\Python\Python39\site-packages\docx\opc\pkgwriter.py", line 32, in write phys_writer = PhysPkgWriter(pkg_file)
File "C:\Users\AppData\Roaming\Python\Python39\site-packages\docx\opc\phys_pkg.py", line 141, in __init__self._zipf = ZipFile(pkg_file, 'w', compression=ZIP_DEFLATED)
File "C:\Program Files\Python39\lib\zipfile.py", line 1239, in __init__self.fp = io.open(file, filemode)
FileNotFoundError: [Errno 2] No such file or directory: './final Report Cards/Tester_111111_A1B _Final Report Cards.docx'

谢谢大家!

好像是
点?您正在尝试返回目录吗?可能是
“/{}\u final Report Cards/{}\u final Report Cards.docx”
或者请检查您的文件。它似乎是
点?您正在尝试返回目录吗?可能是”。/final Report Cards/{}\u final Report Cards.docx“,或者请检查您的文件。
os.mkdir("./Final Report Cards_{}".format(context["cohort"]))
  for context in contexts:
  tpl = DocxTemplate("Final report card  template for Pathway.docx")
  tpl.render(context)
  file_name = str(context["name"]) + "_" + str(context["student_number"]) + "_" + str(context["cohort"])
  tpl.save("./final Report Cards/{}_Final Report Cards.docx".format(file_name))