title: How to use text result of a function outside of function and write it to Word document
body: <p>My program (ideally) extracts from the web a list of elements and then sends the result to a Word doc, saves it and closes it. </p>
  
  <p>All questions I find previously asked here don't cover this problem. How can I print the list text output of the function <code>var()</code> into at <code>p.runs[4]</code> in the Word file? I guess something about the <code>return</code> word would help? but nothing I've tried works.</p>
  
  <pre><code>import selenium.webdriver as webdriver
  
  def var():
      browser = webdriver.Firefox()
      browser.get('https://jobs.theguardian.com/searchjobs/?LocationId=1500&amp;keywords=personal+assistant&amp;radialtown=London+(Central)%2c+London+(Greater)&amp;countrycode=GB')
      #elem = browser.find_elements_by_class_name('lister__header')
      elem = browser.find_elements_by_xpath('//h3/a/span')
      for el in elem:
          var.printText = print(el.text)
      browser.close()
  var()
  
  import docx
  d = docx.Document('C:\\Users\\sk\\Desktop\\test.docx')
  p = d.paragraphs[3]
  p.runs[4].text = var.printText    #HERE IS WHERE I NEED TO PLACE THE TEXT LIST OUTPUT of var.printText
  
  d.save('C:\\Users\\sk\\Desktop\\test.docx')
  </code></pre>
  
  <p>When I run this program, only the word "NONE" is written to the word file, and this is the console result:</p>
  
  <pre><code>C:\Python34\python.exe C:/Users/sk/PycharmProjects/test/temperase.py
  Designer, The Labour Party
  Graduate Display Marketing Account Manager
   # snip...
  HR Administrator – Recruitment &amp; Training
  Secondary Teaching Assistant - Immediate start supporting across all subjects
  Traceback (most recent call last):
    File "C:/Users/sk/PycharmProjects/test/temperase.py", line 22, in &lt;module&gt;
      p.runs[4].text = var.printText
    File "C:\Python34\lib\site-packages\docx\text\run.py", line 163, in text
      self._r.text = text
    File "C:\Python34\lib\site-packages\docx\oxml\text\run.py", line 104, in text
      _RunContentAppender.append_to_run_from_text(self, text)
    File "C:\Python34\lib\site-packages\docx\oxml\text\run.py", line 134, in append_to_run_from_text
      appender.add_text(text)
    File "C:\Python34\lib\site-packages\docx\oxml\text\run.py", line 141, in add_text
      for char in text:
  TypeError: 'NoneType' object is not iterable
  </code></pre>