difficulty with opening file- updated
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
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?
Hello, I posted this issue and thought I had resolved it because I only get this error intermittently- and cannot figure out why. Initially I thought perhaps it was an os.walk issue, then I thought perhaps it was an issue with my filepaths having spaces or even particular files, but I've played around and the only thing I consistently get is the self.fp = io.open(file, filemode). Any advice on what may be causing this and how to get around it is appreciated.