title: How does sys._getframe(1).f_lineno function?
body: <p>I have found this test code and run it with various pieces of code and found it to be correct, but I am not able to understand how it written and what this line of code is doing and how it is doing it:</p>
  
  <pre><code>linenum = sys._getframe(1).f_lineno
  </code></pre>
  
  <p>Can anyone please me tell me the working of the above line of code? The complete block of code is:</p>
  
  <pre><code>import sys
  
  def test(did_pass):
      """  Print the result of a test.  """
      linenum = sys._getframe(1).f_lineno   # Get the caller's line number.
      if did_pass:
          msg = "Test at line {0} ok.".format(linenum)
      else:
          msg = ("Test at line {0} FAILED.".format(linenum))
      print(msg)
  </code></pre>