title: Python: passing instance variable to class method
body: <p>I am using <code>xlsxwriter</code> and I have created a class where I have created a workbook. Then I have added 2 worksheets to it.
  Now I have written a method that's writing data to one of the worksheets, but now I would like to use it on both worksheets. This is a simple example to explain the situation:</p>
  
  <pre><code>import xlsxwriter
  
  class ExcelWorkbook():
      def __init__(self, filename):
          self.wb = xlsxwriter.Workbook(filename)
          self.ws1 = self.wb.add_worksheet('Num')
          self.ws1LineCount = 0
          self.ws2 = self.wb.add_worksheet('Result')
          self.ws2LineCount = 0
  
      def write_data(self, data, title):        
          self.ws1.write_row(self.ws1LineCount, 0, title)
          self.ws1LineCount += 1
          self.ws1.write_row(self.ws1LineCount, 0, data)
          self.ws1LineCount += 1
  
  xlsxWorkbook = ExcelWorkbook('Test2.xlsx')
  numArr = (0.000000520593523979187, 13.123456789, 1.789456, 0.002345, 0.00123, 1)
  titleBar = ('Date', 'quantity', 'Average [m]', 'Standard Dev [m]', 'Test', 'Success')
  xlsxWorkbook.write_data(numArr, titleBar)
  </code></pre>
  
  <p>Now I'd like to use the <code>write_data</code> method for both worksheets, so I thought I'd pass the worksheet as a parameter, but unfortunately it's not that simple, as I cannot pass the instance variable <code>self.ws1</code> or <code>self.ws2</code>.</p>
  
  <p>So the question is: how can I do that? </p>
  
  <p>I came up with a very nasty solution, like this:</p>
  
  <pre><code>def write_data(self, data, title, instance = 'ws1'):
      if instance == 'ws1':
          instance = self.ws1
          lineCounter = self.ws1LineCount
      elif instance == 'ws2':
          instance = self.ws2
          lineCounter = self.ws2LineCount
  
      instance.write_row(self.ws1LineCount, 0, title)
      lineCounter += 1
      instance.write_row(self.ws1LineCount, 0, data)
      lineCounter += 1
  </code></pre>
  
  <p>but honestly I don't like it. Is there a proper way to do it, or is it like a completely unreasonable thing?</p>