How can I create a Word document using Python?

A couple ways you can create Word documents using Python:

  • Use COM automation to create a document using the MS Word object model (using pywin32). http://python.net/crew/pirx/spam7/
  • Automate OpenOffice using Python: http://wiki.services.openoffice.org/wiki/Python
  • If rtf format is OK, use the PyRTF library: http://pyrtf.sourceforge.net/

EDIT:

Since COM is out of the question, I suggest the following (inspired by @kcrumley's answer):

Using the UNO library to automate Open Office from python, open the HTML file in OOWriter, then save as .doc.

EDIT2:

There is now a pure Python python-docx project that looks nice (I have not used it).


I tried python-docx with succes, it enables you to make and edit docx within Python