Skip to content

Python development

Joachim Metz edited this page Jul 13, 2022 · 3 revisions

libolecf comes with Python-bindings named pyolecf.

Below are examples how use pyolecf. They assume you have a working version of pyolecf on your system. To build pyolecf see Building.

Import

To be able to use pyolecf in your Python scripts add the following import:

import pyolecf

Get version

The get_version() module function can be used to retrieve the version of the pyolecf.

pyolecf.get_version()

This will return a textual string (Unicode) that contains the libolecf version. Since pyolecf is a wrapper around libolecf it does not have a separate version.

Open file

Open a file by path

olecf_file = pyolecf.file()

olecf_file.open("Test.doc")

...

olecf_file.close()

The explicit call to olecf_file.close() is not required. Close only must be called once all operations on the file have been completed.

Open a file using a file-like object

file_object = open("Test.doc", "rb")

olecf_file = pyolecf.file()

olecf_file.open_file_object(file_object)

...

olecf_file.close()

The explicit call to olecf_file.close() is not required. Close only must be called once all operations on the file have been completed and will not close the file-like object itself.

Also see

import pyolecf

help(pyolecf)
help(pyolecf.file)
Clone this wiki locally