title: Count line no. using python
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/845058/how-to-get-line-count-cheaply-in-python">How to get line count cheaply in Python?</a>  </p>
  </blockquote>
  
  
  
  <p>In my work i need to open a file and count no. of lines in that, i tried with this </p>
  
  <p><code>Last_Line = len(open(File_Name).readlines())</code></p>
  
  <p>It was working fine. Now i have a problem, actual no. of lines in the file is 453, but if i print <code>Last_Line</code> it is showing only 339. If i try </p>
  
  <pre><code>print linecache.getline(File_Name, 350)
  </code></pre>
  
  <p>it is displaying the contents of line no. 350. </p>
  
  <p>I tried opening the file in all modes.
  Whether its problem with file or with my logic?
  Please help.</p>
  
  <p>thank you</p>