call system command inside python and get its result not exit status
<p>i am use python count number of line in the file</p>

<pre><code>def countline(filename):
    num = 0
    for lines in open(filename,"r"):
        num = num + 1
    return num
</code></pre>

<p>but result is wrong when i check it with wc command in terminal
then i tried </p>

<pre><code>import subprocess
subprocess.call("wc -l xh-2.txt",shell=True)
</code></pre>

<p>it returns exit status 0/1 but i want a number !
i know <code>print os.popen("wc -l xh-2.txt|cut -d' ' -f1").read()</code> will do the job
but popen is depreciated and why use read() ? like java tostring in python ?</p>

<p>i am confused</p>
