title: Output compiler error to a txt file in python
body: <p>I'm a beginner using python. I want to create a regular expression to capture error messages from compiler output in python. How would I do this?</p>
  
  <p>for example, if the compiler output is the following error message:</p>
  
  <pre><code>Traceback (most recent call last):
    File "sample.py", line 1, in &lt;module&gt;
      hello
  NameError: name 'hello' is not defined
  </code></pre>
  
  <p>I want to be able to only extract only the following string from the output:</p>
  
  <pre><code>NameError: name 'hello' is not defined
  </code></pre>
  
  <p>In this case there is only one error, however I want to extract all the errors the compiler outputs. How do I do this using regular expressions? Or if there is an easier way, I'm open to suggestions</p>