Why does importing subprocess change my output?
<p>I noticed the following using Python 2.5.2 (does not occur using 2.7):</p>

<pre><code>#!/usr/bin/python

import sys

for line in sys.stdin:
   print line,
</code></pre>

<p>Output:</p>

<pre><code>$ echo -e "one\ntwo\nthree" | python test.py
$ one
$ two
$ three
</code></pre>

<p>as expected. However, if I import <code>subprocess</code> to the this script:</p>

<pre><code>#!/usr/bin/python

import sys
import subprocess

for line in sys.stdin:
   print line,
</code></pre>

<p>Output:</p>

<pre><code>$ echo -e "one\ntwo\nthree" | python test.py
$ two
$ three
</code></pre>

<p>What happened to the first line of output?</p>

<p><strong>Update:</strong></p>

<p>I think I may have discovered the root of the problem. I had a file named <code>time.py</code> in my <code>cwd</code>. A <code>time.pyc</code> is being created every time I run the script with <code>subprocess</code> imported, suggesting that <code>./time.py</code> is also being imported. The script runs normally if I delete the <code>.pyc</code> and <code>time.py</code> files; however, there is still the question of why a <code>subprocess</code> import would cause <code>./time.py</code> to be imported as well?</p>

<p>I have narrowed it down even further to the exact line in <code>time.py</code> that causes the strange behaviour. I have stripped down the working dir and file content to just that which affects the output:</p>

<p><strong>test.py</strong></p>

<pre><code>#!/usr/bin/python

import sys
import subprocess

for line in sys.stdin:
   print line,
</code></pre>

<p><strong>time.py</strong></p>

<pre><code>#!/usr/bin/python

import sys

for line in sys.stdin:
   hour = re.search(r'\b([0-9]{2}):', line).group(1)
</code></pre>

<p>Running <code>test.py</code> with any kind of input results in the first line of output being omitted and <code>time.pyc</code> being created.</p>
