title: In Python, is referencing an instance variable from a staticmethod possible?
body: <p>I know the question has been asked before, but I find myself bumping into situations where a staticmethod is most appropriate, but there is also a need to reference an instance variable inside this class. As an example, lets say I have the following class:</p>
  
  <pre><code>class ExampleClass(object):
      def __init__(self, filename = 'defaultFilename'):
          self.file_name = filename
  
      @staticmethod
      def doSomethingWithFiles(file_2, file_1 = None):
           #if user didn't supply a file use the instance variable 
           if file_1 is None:
              # no idea how to handle the uninitialized class case to create
              # self.file_name. 
              file_1 = __class__.__init__().__dict__['file_name'] &lt;--- this seems sketchy
           else:
              file_1 = file_1
           with open(file_1, 'r') as f1, open(file_2, 'w') as f2:
              .....you get the idea...
  
      def moreMethodsThatUseSelf(self):
          pass
  </code></pre>
  
  <p>Now suppose I had  a few instances of the ExampleClass (E1, E2, E3) with different filenames passed into __init__, but want to retain the ability to use either an uninitialized class ExampleClass.doSomethingWithFiles(file_2 = E1.file_name, file_1 = E2.file_name) or E1.doSomethingWithFiles(file_2 = E2.file_name, file_1 = 'some_other_file') as the situation requires.</p>
  
  <p>Is there any reason for me to trying to find a way to do what I am thinking, or am I making a mess?</p>
  
  <p><strong>UPDATE</strong>
  I think the comments are helpful and I also think it's an issue I'm encountering due to bad design. </p>
  
  <p>The issue started out as a way to prevent concurrent access to HDF5 files by giving each class instance an rlock that I could use as a context manager for preventing any other attempts to access the file while it was in use. Each class instance had it's own rlock it acquired and released when done with whatever it needed to do. I was also using @staticmethod to perform a routine that then generated a file which was passed into it's own <strong>init</strong>() and was unique to each class instance. At the time it seemed clever, but I regret it. I also think I am entirely unsure of when @staticmethods are ever appropriate and maybe was confusing it with @classmethods, but a class variable would no longer make the rlocks and files that are unique to my class instances possible. I think I should probably just think more about design vs. trying to justify using a class definition I do not really understand in a manner it was designed to protect against. </p>