How to read .odt using Python?

16.4k views Asked by At

I tried to read ".odt" files using python with "odfpy" library, but it still doesn't work.

How can I read an ".odt" file using Python?

1

There are 1 answers

6
Nidhin Sajeev On

First install odfpy library then,

In [21]: from odf import text, teletype
    ...: from odf.opendocument import load
    ...: 
    ...: textdoc = load("your.odt")
    ...: allparas = textdoc.getElementsByType(text.P)
    ...: teletype.extractText(allparas[0])
    ...: 
Out[21]: 'Hello World!'