Write Python strings to file for reading by a Perl script
<p>I'd like to write results to a txt file in Python, where each line needs to be in the format sentence-tab-score:</p>

<p><code>&lt;s&gt; This is the sentence &lt;/s&gt;  42</code></p>

<p>The intent is to have a "score_results" Perl script read the sentences and scores, where each line is parsed w/ <code>@fields = split(/\t/)</code>:</p>

<pre><code>$count = 0;
$best = "";
$bestlp = -1000000;

while (&lt;&gt;) {
        s/\s+[\r\n]+$//o;
        @fields = split(/\t/);
        if ($fields[1] &gt; $bestlp) {
                $bestlp = $fields[1];
                $best = $fields[0];
        }

        if ((++$count % 5) == 0) {
                print "$best\n";
                $bestlp = -1000000;
        }
}
</code></pre>

<p>My issue is writing the results sentences in Python, with </p>

<pre><code>with open("results.txt", "wb") as fout:
    for sentence, score in zip(resultsSentences, resultsScores):
        fout.write(sentence + "\t" + str(score) + "\n")
</code></pre>

<p>doesn't work because the tabs in the Python-written file end up as new lines, and thus not recognized in the Perl script as a tab. The first few lines of "results.txt" look like</p>

<pre><code>&lt;s&gt; I have seen it on him , and could write to it &lt;/s&gt; 
    42.0
&lt;s&gt; I have seen it on him , and could migrate to it &lt;/s&gt; 
    42.0
&lt;s&gt; I have seen it on him , and could climb to it &lt;/s&gt; 
    42.0
</code></pre>

<p>But the example results that run with the Perl script look like</p>

<pre><code>&lt;s&gt; I have seen it on him , and could write to it &lt;/s&gt;  -46.8152390767177
&lt;s&gt; I have seen it on him , and could migrate to it &lt;/s&gt;    -50.5058224637686
&lt;s&gt; I have seen it on him , and could climb to it &lt;/s&gt;  -48.5949070950928
</code></pre>

<p>And then the "score_results" Perl script runs with the bash call
<code>cat results.txt | ./score_results.pl &gt; scores.temp</code></p>

<p>Given I'd prefer to use the provided Perl script, how can I modify the script and/or write my results sentences differently?</p>