title: Absolute path of a file object
body: <p>This has been discussed on StackOverflow before - I am trying to find a good way to find the absolute path of a file object, but I need it to be robust to <code>os.chdir()</code>, so cannot use </p>
  
  <pre><code>f = file('test')
  os.path.abspath(f.name)
  </code></pre>
  
  <p>Instead, I was wondering whether the following is a good solution - basically extending the file class so that on opening, the absolute path of the file is saved:</p>
  
  <pre><code>class File(file):
  
      def __init__(self, filename, *args, **kwargs):
          self.abspath = os.path.abspath(filename)
          file.__init__(self, filename, *args, **kwargs)
  </code></pre>
  
  <p>Then one can do</p>
  
  <pre><code>f = File('test','rb')
  os.chdir('some_directory')
  f.abspath # absolute path can be accessed like this
  </code></pre>
  
  <p>Are there any risks with doing this?</p>