title: How to get execution of python print statements as a string?
body: <p>I am writing a python script which contains a list containing python print statements as a string. In my function, I am using a for loop to run exec function to run those statements.</p>
  
  <p>Here is my function:</p>
  
  <pre><code>g_list = ["print('Wow!')\n", "print('Great!')\n", "print('Epic!')\n"]
  
  def run_statements():
      for item in g_list:
          exec(item)
  </code></pre>
  
  <p>When I run <code>run_statements()</code> function, I get the following output:</p>
  
  <pre><code>Wow! 
  Great! 
  Epic!
  </code></pre>
  
  <p>Basically, I want to save the output as a string so that later, I can save it to my database.</p>
  
  <p>Does anyone have any idea how can I do it?</p>
  
  <p><strong>EDIT:</strong> At the following question: <a href="https://stackoverflow.com/questions/3906232/python-get-the-print-output-in-an-exec-statement">python: get the print output in an exec statement</a> He is trying to get output, My question is different in a way that I am trying to get output as a string</p>