Opening a document
from docx import Document
document = Document()
document.save('test.docx')
REALLY opening a document
document = Document('existing-document-file.docx')
document.save('new-file-name.docx')
Opening a ‘file-like’ document
f = open('foobar.docx', 'rb')
document = Document(f)
f.close()
# or
with open('foobar.docx', 'rb') as f:
source_stream = StringIO(f.read())
document = Document(source_stream)
source_stream.close()
...
target_stream = StringIO()
document.save(target_stream)