Determining when a file is an Open Office Document

Ross Ridge rridge at csclub.uwaterloo.ca
Thu Jan 18 20:57:00 EST 2007


tubby wrote:
> Silly question, but here goes... what's a good way to determine when a
> file is an Open Office document? I could look at the file extension, but
> it seems there would be a better way. VI shows this info in the files:
>
> mimetypeapplication/vnd.oasis.opendocument.textPK

It's a ZIP archive.  The info you've found are the file name
"mimetype", the uncompressed contents of that file
"application/vnd.oasis.opendocument.text", and part of the ZIP magic
number "PK".  You should be able to use the "zipfile" module to check
to see if the file a ZIP file, if it has a member named "mimetype" and
if the contents of the file match one of the OpenOffice MIME types.

                                      Ross Ridge




More information about the Python-list mailing list