title: Python:Detect if the current line in file read is the last one
body: <p>I am reading a file in Python line by line and I need to know which line is the last one while  reading,something like this:</p>
  
  <pre><code> f = open("myfile.txt")
   for line in f:
      if line is lastline:
         #do smth
  </code></pre>
  
  <p>From the <a href="https://stackoverflow.com/questions/7167008/efficiently-finding-the-last-line-in-a-text-file">examples</a> I found it involves seeks and complete file readouts to count lines,etc.Can I just detect that the current line is the last one? I tried to go and check for "\n" existence ,but in many cases the last lines is not followed by backslash N.</p>
  
  <p>Sorry if my question is redundant as I didn't find the answer on SO</p>