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?

(4 votes)
Loading...

Similar Posts

Subscribe
Notify of
4 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
mihisu
1 year ago

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?

mihisu
1 year ago
Reply to  billythekidd0

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.]