title: How do I create a text file in jupyter notebook, from the output from my code
body: <p>How can I create and append the output of my code to a txt file? I have a lot of code.</p>
  <p>This is just a small example of what I'm trying to do:</p>
  <pre><code>def output_txt():
    def blop(a,b):ans = a + b
              print(ans)
          blop(2,3)
          x = 'Cool Stuff'
          print(x)
  
  
  def main(x):
      f = open('demo.txt', 'a+')
      f.write(str(output_txt))
      f.close
      
  main(x)
  
  f = open('demo.txt', 'r')
  contents = f.read()
  print(contents)
  </code></pre>
  <p>But the output gives me this:</p>
  <p>cool bananas&lt;function output_txt at 0x0000017AA66F0F78&gt;&lt;function output_txt at 0x0000017AA66F0B88&gt;&lt;function output_txt at 0x0000017AA66F0948&gt;</p>