title: Is there a way to copy the contents of a Word file to a list for later use?
body: <p>I am trying to copy the contents of a word file to a list that I can access later to insert into the a new word file.  Simply put, I am trying to a function that performs a copy and paste on a selection from the Word document at a time.
  The problem I am running into is the blank "lines"/spacing between Sections.  This spacing is important for the layout of the document.  I can copy the lines that contain objects and numbers, but when it comes to a blank line.  It spits out an Error.  </p>
  
  <p>I have searched this forum and others for a solution, and haven't found anything relevant to this specific issue</p>
  
  <pre><code>import tkinter as tk
  from tkinter.filedialog import askopenfilename
  from docx import Document  # Invokes Document command from docx
  
  
  def get_para_data(output_doc_name, paragraph):
  """
  Write the run to the new file and then set its font, bold, alignment, 
  color etc. data.
  """
  
  output_para = output_doc_name.add_paragraph()
      for run in paragraph.runs:
          output_run = output_para.add_run(run.text)
          # Run's bold data
          output_run.bold = run.bold
          # Run's italic data
          output_run.italic = run.italic
          # Run's underline data
          output_run.underline = run.underline
          # Run's color data
          output_run.font.color.rgb = run.font.color.rgb
          # Run's font data
          output_run.style.name = run.style.name
          # Paragraph's alignment data
          output_para.paragraph_format.alignment = 
          paragraph.paragraph_format.alignment
  return output_run
  n = 4
  
  # IMPORT WORD DOCUMENT
  root = tk.Tk()
  root.withdraw()
  doc_path = askopenfilename(title="Choose Word File")  # returns the file 
  path as variable for future use
  document = Document(doc_path)  # Imports Word Document to Modify
  t = len(document.paragraphs)  # gives the number of lines in document
  print('Total Number of lines =', t)  # this is a check for now
  result = Document()
  output_paragraph = [None]*t
  i = 0
  for para in document.paragraphs:
      output_paragraph[i] = get_para_data(result, document.paragraphs[i])
      i += 1
  </code></pre>
  
  <p>The first iteration runs through great, but as soon as we get to the second iteration and the blank line it crashes and give several errors.  </p>
  
  <blockquote>
    <p>Traceback (most recent call last):   File "C:\Program
    Files\JetBrains\PyCharm Community Edition
    2018.3.2\helpers\pydev\pydevd.py", line 1741, in 
        main()</p>
    
    <p>File "C:\Program Files\JetBrains\PyCharm Community Edition
    2018.3.2\helpers\pydev\pydevd.py", line 1735, in main
        globals = debugger.run(setup['file'], None, None, is_module)    </p>
    
    <p>File "C:\Program Files\JetBrains\PyCharm Community Edition
    2018.3.2\helpers\pydev\pydevd.py", line 1135, in run
        pydev_imports.execfile(file, globals, locals)  # execute the script    </p>
    
    <p>File "C:\Program Files\JetBrains\PyCharm Community Edition
    2018.3.2\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile
        exec(compile(contents+"\n", file, 'exec'), glob, loc)   </p>
    
    <p>File "C:/Users/SmithC113/PycharmProjects/ASCII_Word/point_creator.py", line
    51, in 
        output_para[i] = get_para_data(result, document.paragraphs[i])    </p>
    
    <p>File "C:/Users/SmithC113/PycharmProjects/ASCII_Word/point_creator.py",
    line 35, in get_para_data
        return output_run UnboundLocalError: local variable 'output_run' referenced before assignment</p>
  </blockquote>