My Python program is behaving strangely?
I'm currently trying to write a function in Python that allows me to extract text from .docx (Word) files. I'm using the pyth-docx library for this. My program works as intended: if I create a .docx file in Python and then use my function, it returns the text.
However, for Word documents I've modified or created myself, it can't find the path and returns a PackageNotFoundError. I found a way to check whether my file is a zip file online. So I tried zipfile, and my saved Word documents aren't zip files. What's going wrong here? Here's my code again for verification:
doc = docx.Document()
doc.add_paragraph("Hello")
doc.save(test_path")
print(is_zipfile(test_path))
//output = true
if I then go to this test_path, type a number and press save- >
//output = false
Are modern docx documents no longer zip files? Or what's wrong with me?
However, the “.docx” documents should continue to be ZIP files. I’ve also tested this with my files I created with Microsoft Word. There is_zipfile() returns a chest everywhere.
What did you edit the file (if you typed the number)? With Microsoft Word?
Can you possibly. provide one of these files that does not work?
I’m doing this with Microsoft Word. But I’m at the workstation, could they have any encryption while saving the file type?
Can you just upload files here or do you mean by Dropbox?
Hmm, if that can be a encryption, I can judge hard. Actually, python shouldn’t notice anything about encryption via the operating system and have access to the unencrypted data.
There is no way to upload the files directly. You should upload it somewhere else and then give us access to the file uploaded elsewhere.
[Of course, you should note if you want to share the corresponding files here in public. That was just a suggestion that I might. also could look at whether I notice anything about the files.]
WOOOW, I have put my Word program on public and now it works. Thanks for your answers, that helped me very much. I will no longer classify files after their endings devinitiv :D. I don’t know what’s going on when I put it on staff, but apparently it’s not a .zip file anymore despite .docx extension. I don’t get a solution