docx to list in python
<p>I am trying to read a docx file and to add the text to a list.
Now I need the list to contain lines from the docx file.</p>

<p>example:</p>

<p>docx file:</p>

<pre><code>"Hello, my name is blabla,
I am 30 years old.
I have two kids."
</code></pre>

<p>result:</p>

<pre><code>['Hello, my name is blabla', 'I am 30 years old', 'I have two kids']
</code></pre>

<p>I cant get it to work.</p>

<p>Using the <code>docx2txt</code> module from here:
<a href="https://github.com/ankushshah89/python-docx2txt" rel="nofollow">github link</a></p>

<p>There is only one command of process and it returns all the text from docx file.</p>

<p>Also I would like it to keep the special characters like <code>":\-\.\,"</code></p>

<p><strong>docx2txt</strong> module reads docx file and converts it in text format. </p>

<p>You need to split above output using <code>splitlines()</code> and store it in list.</p>

<p><strong>Code (Comments inline) :</strong></p>

<pre><code>import docx2txt

text = docx2txt.process("a.docx")

#Prints output after converting
print ("After converting text is ",text)

content = []
for line in text.splitlines():
  #This will ignore empty/blank lines. 
  if line != '':
    #Append to list
    content.append(line)

print (content)
</code></pre>

<p><strong>Output:</strong></p>

<pre><code>C:\Users\dinesh_pundkar\Desktop&gt;python c.py
After converting text is
 Hello, my name is blabla.

I am 30 years old.

I have two kids.

 List is  ['Hello, my name is blabla.', 'I am 30 years old. ', 'I have two kids.']

C:\Users\dinesh_pundkar\Desktop&gt;
</code></pre>

python python-2.7