Skip to content

difficulty with opening file- updated #37

@mmiesner

Description

@mmiesner

Hello. I'll paste my code and error below. I'm not sure if this is an issue with my code or with the docx2txt module or zipfile.py.
Please advise.

import re
from csv import writer
import docx2txt
import os

directory = 'written evaluations/'

def writefile():
with open("/providerfax.csv", "a", newline='') as f_object:
# Pass the CSV file object to the writer() function
writer_object = writer(f_object)
# Result - a writer object
# Pass the data in the list as an argument into the writerow() function
writer_object.writerow(line)
# Close the file object
f_object.close()

for subdir, dirs, files in os.walk(directory):
for files in files:
print(os.path.join(subdir, files))
if files.endswith(".docx"):
text = docx2txt.process(files)
provider = re.findall(r'To:\s+(.)', text)
fax = re.findall(r'Number:\s+(.
)',text)
global line
line = provider + fax
writefile()

and the error:

written evaluations/(patient name)Evaluation.docx
Traceback (most recent call last):
File "/myscript.py", line 24, in
text = docx2txt.process(files)
File "venv2/lib/python3.8/site-packages/docx2txt/docx2txt.py", line 76, in process
zipf = zipfile.ZipFile(docx)
File "/usr/lib/python3.8/zipfile.py", line 1251, in init
self.fp = io.open(file, filemode)
FileNotFoundError: [Errno 2] No such file or directory: '(P:atient Name)Evaluation.docx'

Process finished with exit code 1

But if I go to the patient name folder, I can verify that the file is there, and I can open it with libreoffice and it is a .docx.

What is causing this error and how can I resolve it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions