title: Check if two file pointers point to same file in Python
body: <p>How do I check if two file pointers point to the same file or not.</p>
  
  <pre><code>&gt;&gt;&gt; fp1 = open("/data/logs/perf.log", "r")
  &gt;&gt;&gt; fp1
  &lt;open file '/data/logs/perf.log', mode 'r' at 0x7f5adc07cc00&gt;
  &gt;&gt;&gt; fp2 = open("/data/logs/perf.log", "r")
  &gt;&gt;&gt; fp2
  &lt;open file '/data/logs/perf.log', mode 'r' at 0x7f5adc07cd20&gt;
  &gt;&gt;&gt; fp1 == fp2
  False
  &gt;&gt;&gt; fp1 is fp2
  False
  </code></pre>
  
  <p>My <strong>use case</strong> is I am watching a file for changes and doing something, but logback rolls over this file to old date and creates a new file. But the file pointer variable in python is still pointing to the old file. If <code>fp1 != fp2</code>, I would like to update <code>fp1</code> to new file.</p>
  
  <p>Why <code>.name</code> doesn't work?
  When I tried, </p>
  
  <pre><code>mv /data/logs/perf.log /data/logs/perfNew.log
  echo abctest &gt;&gt; /data/logs/perfNew.log
  </code></pre>
  
  <p>even then the name still is the old one.</p>
  
  <pre><code>&gt;&gt;&gt; fp1.readline()
  'abctest\n'
  &gt;&gt;&gt; fp1.name
  '/data/logs/perf.log'
  </code></pre>