Writing items to file on separate lines without blank line at the end
<p>I have a file with a bunch of text that I want to tear through, match a bunch of things and then write these items to separate lines in a new file.</p>

<p>This is the basics of the code I have put together: </p>

<pre><code>f = open('this.txt', 'r')
g = open('that.txt', 'w')
text = f.read()
matches = re.findall('', text) # do some re matching here
for i in matches:
    a = i[0] + '\n'
    g.write(a)
f.close()
g.close()
</code></pre>

<p>My issue is I want each matched item on a new line (hence the '\n') but I don't want a blank line at the end of the file. </p>

<p>I guess I need to not have the last item in the file being trailed by a new line character.</p>

<p>What is the Pythonic way of sorting this out? Also, is the way I have set this up in my code the best way of doing this, or the most Pythonic?</p>
