Leggere file Word con Python e python-docx
Dovendo leggere dei file Word in formato docx con Python, ho usato la libreria python-docx.
Oggi vediamo un esempio veloce, giusto per capire come usare la libreria.
Prima di tutto installiamola tramite pip:
(venv) $ pip3 install python-docx
Come vedete siamo in ambiente virtuale.
Fatto questo vediamo un esempio di codice Python che legge tutto il testo paragrafo per paragrafo:
from docx import Document
d = Document('test.docx')
for p in d.paragraphs:
print(p.text)
Non se funziona anche con i formati più vecchi di Word, ma sarebbe da provare.
Enjoy!
pythom pip word docx python-docx
Commentami!