Reputation: 171
Novice programmer here. I'm trying to learn how to open/edit/save word document files. I'm on windows 7 64bit and have Microsoft Word 2010. I'm following this guide: https://python-docx.readthedocs.org/en/latest/user/quickstart.html
I'm following the first section "Opening a document" and type in the first two lines and nothing opens. So I must be doing something wrong. Can't get word to open at all. Any advice?
Upvotes: 2
Views: 1524
Reputation: 113930
what are you trying to do ... thats creating a new document ... not opening it in word
to open a file
os.startfile(r"C:\Some\Folder\doc1.docx")
what docx
(python module you referenced) is for is creating new docx files that you can then open in word after you have created them
consider the following
from docx import Document
import os
document = Document() #create a new document
paragraph = document.add_paragraph('Lorem ipsum dolor sit amet.')
document.save('test.docx') #save it to the filesystem
os.startfile("test.docx") #open it with the default handler for docx (usually word)
Upvotes: 2