title: Calling a static method from class initialised elsewhere
body: <p>I have the following class for creating, writing to and closing a LockFile.</p>
  
  <pre><code>class LockFileManager:
      def __init__(self,fname):
          """
          Create FileLock and Prepender objects.
          """
          self.fname = fname
  
          self.file_lock = FileLock(fname)
          self.file_lock.acquire()
  
          self.file_writer = Prepender(fname)
  
          print "LockFile: File lock and writer acquired!\n"
  
      @staticmethod
      def add_command(command):
          """
          Prepend a command to the LockFile
          """
          print "LockFile: Adding command: " + command + "\n"
          self.file_writer.write(command)
  
      def end(self):
          """
          Close and remove the LockFile
          """
          print "LockFile: Closing &amp; Removing LockFile:\n"
          self.file_writer.close()
          self.file_lock.release()
  
          os.remove(self.fname)
  </code></pre>
  
  <p>In my main body of code, I would initialise the class like so:</p>
  
  <pre><code>lockfile = LockFileManager("lockfile.txt")
  </code></pre>
  
  <p>Then elsewhere in my code, I would like to write to the file:</p>
  
  <pre><code>LockFileManager.add_command("Write to LockFile provided at initialisation from some arbitrary point in the code ")
  </code></pre>
  
  <p>Then at the end of the main body of code, call <code>lockfile.exit()</code></p>
  
  <p>When I try to add a command, I get <code>NameError occurred: global name 'self' is not defined</code>. If <code>self.file_writer.write(command)</code> is changed to <code>file_writer.write(command)</code> then it does not know what <code>file_writer</code> is. </p>
  
  <p>Does anybody know the proper way to go about this? Cheers!</p>