<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Lesson 45
Step1:  Documents have a few more features than plaintext files. They have the following objects in this module
Step2:  We then use the Document() function to open the word document as a document object.
For this example, we will be using 'demo.docx'.
Step3:  We can list the paragraphs within this document object. 
A paragraph object is any text seperated by a newline ('Enter').
Step4:  Every paragraph object includes a .text variable containing the string of the document.
Step5:  As you can see, these paragraph objects match the text in the document. 
We will save the paragraph object to a holder variable.
Step6:  Paragraph objects hold run objects. 
A run object is any text that is has a different style (bold, underline, size, etc.)
Step7:  Run objects have a .bold or .italics variable, identifying whether that run has that style property.
Step8:  We can save style attributes using this approach.
Step9:  We can save our changes by using the .save method on the document object.
It will be saved as 'demo2.docx'.
Step10:  Word also has document themes and styles such as 'Normal' or 'Heading 1', etc. These are accessible for paragraph objects.
Step11:  This module can also be used to create blank word documents in memory using the Document() function.
Step12:  We can now add paragraphs to this document object.
Step13:  We can save this created document to the hard drive using the .save() method again. It will be saved here as demo4.docx.
Step14:  We can also create runs within these paragraph objects.
Step15:  You cannot insert paragraph and run functions anywhere but the end, but there is a way to edit files by opening a new document and mirroring the old document with changes.
It still allows for some effecient batch management. Here is an example of a function to get all the Text from a word document.
Step16:  We will test it on demo.docx and demo4.docx.
<ASSISTANT_TASK:>
Python Code:
import docx
Explanation: Lesson 45:
Reading and Editing Word Documents
Python can also be used to create and modify Word documents. 
The python-docx module can interact with Word document files, with .docx filetypes. While the module is installed via python-docx, it is imported with docx.
End of explanation
import os
os.chdir('files')
Explanation: Documents have a few more features than plaintext files. They have the following objects in this module:
* The entire document is contained within the document object.
* The document object contains paragraph objects, which is each paragraph in the document.
* The paragraph object contains one or more run objects.
We first navigate into the subdirectory containing the Word documents, using relative or absolute paths.
End of explanation
d = docx.Document('demo.docx')
type(d)
Explanation: We then use the Document() function to open the word document as a document object.
For this example, we will be using 'demo.docx'.
End of explanation
d.paragraphs
d.paragraphs[0]
Explanation: We can list the paragraphs within this document object. 
A paragraph object is any text seperated by a newline ('Enter').
End of explanation
d.paragraphs[0].text
d.paragraphs[1].text
Explanation: Every paragraph object includes a .text variable containing the string of the document.
End of explanation
p = d.paragraphs[1]
Explanation: As you can see, these paragraph objects match the text in the document. 
We will save the paragraph object to a holder variable.
End of explanation
p.runs
p.runs[0].text
p.runs[1].text
p.runs[2].text
Explanation: Paragraph objects hold run objects. 
A run object is any text that is has a different style (bold, underline, size, etc.)
End of explanation
p.runs[2].bold
Explanation: Run objects have a .bold or .italics variable, identifying whether that run has that style property.
End of explanation
p.runs[3].text
p.runs[3].underline = True 
Explanation: We can save style attributes using this approach.
End of explanation
d.save('demo2.docx')
Explanation: We can save our changes by using the .save method on the document object.
It will be saved as 'demo2.docx'.
End of explanation
p.style = 'Title' 
d.save('demo2.docx')
Explanation: Word also has document themes and styles such as 'Normal' or 'Heading 1', etc. These are accessible for paragraph objects.
End of explanation
d = docx.Document()
Explanation: This module can also be used to create blank word documents in memory using the Document() function.
End of explanation
d.add_paragraph('This is a paragraph.')
d.add_paragraph('This is another paragraph.')
Explanation: We can now add paragraphs to this document object.
End of explanation
d.save('demo4.docx')
Explanation: We can save this created document to the hard drive using the .save() method again. It will be saved here as demo4.docx.
End of explanation
# Select the first paragraph we created.
p = d.paragraphs[0]
# Add a new run to that paragraph.
p.add_run('This is a new run')
# Set the newly added run (Index 1) to a True bold variable
p.runs[1].bold = True
# Save changes
d.save('demo4.docx')
Explanation: We can also create runs within these paragraph objects.
End of explanation
import docx
# Create a function to get text from a file
def getText(filename):
    # Read the word document
    doc = docx.Document(filename)
    # Create an empty set to store words
    fullText = []
    # for each paragraph in the document paragraph list
    for para in doc.paragraphs:
        # Append the empty set with the new paragraph objects
        fullText.append(para.text)
    # Join the full text with newlines
    return '\n'.join(fullText)
Explanation: You cannot insert paragraph and run functions anywhere but the end, but there is a way to edit files by opening a new document and mirroring the old document with changes.
It still allows for some effecient batch management. Here is an example of a function to get all the Text from a word document.
End of explanation
print(getText('demo.docx'))
print(getText('demo4.docx'))
Explanation: We will test it on demo.docx and demo4.docx.
End of explanation
<END_TASK>