title: Capturing python re.compile() with re.DEBUG flag terminal output
body: <p>When using <code>re.compile()</code> with the <code>re.DEBUG</code> flag, the parse information is printed to the console.<br>
  For example, running <code>pattern = re.compile(r'[ab]+', re.DEBUG)</code> you get the following output printed in the console: <br></p>
  <pre class="lang-py prettyprint-override"><code>MAX_REPEAT 1 MAXREPEAT
    IN
      LITERAL 97
      LITERAL 98
  </code></pre>
  <p>I want to get this parse tree and keep it in a variable so I can process it, however I don't find where this output is saved if at all.</p>
  <p>Note: I am able to get the output by running the compile as a subprocess and capturing the output with</p>
  <pre class="lang-py prettyprint-override"><code>proc = subprocess.Popen([&quot;python&quot;, &quot;-c&quot;, &quot;import re; re.compile(r'[ab]+', re.DEBUG)&quot;], stdout=subprocess.PIPE)
  out = proc.communicate()[0]
  </code></pre>
  <p>But it feels a bit of an overkill.</p>
  <p>Is there any simpler way of getting the debug output?</p>