title: Python OOP and Recursion: when to put "self" and when not to
body: <p>In a recursive function in Python OOP, the use of the prefix &quot;self.&quot; seems to get a bit murky.</p>
  <pre><code>class Tree:
      def __init__():
          ...
  
      def flatten(self, ...):
        nodeQueue = queue.Queue(10)
  
        ...
  
        nodeQueue.put(...)
        nodeQueue.get()
  
        ...
  
        self.flatten(...)
        ...
  </code></pre>
  <p>Q1. If <em>nodeQueue</em> is accessed across every layer of the recursion, should it be:
  self.<em>nodeQueue</em> OR <em>nodeQueue</em></p>
  <p>Q2. The parameter of <em>flatten(...)</em> denoted by <code>...</code>, should that have the &quot;self&quot; prefix as well? Concretely, let one of the parameters be <code>layerDepth = 0</code>. And at each recursion call, <code>layerDepth += 1</code> happens. So, should it be <code>self.layerDepth ...</code> OR <code>layerDepth ...</code></p>
  <p>Given my two questions, I hope for an answer that outlines the general rules of the usage of <code>self.</code> in the context of recursive function in OOP.</p>