title: Python helper function scope
body: <p>So, I have a whole bunch of things doing basically the same thing with only a slight change in input. Perfect candidate to be function'd out and called each time with different parameters, right?</p>
  
  <p>Apparently, python thinks I'm wrong.</p>
  
  <p>So, here's a boiled-down version of my problem</p>
  
  <pre><code>def main():
      x = 10
  
      def helper(n):
        if (x &gt; n):
            x -= n
  </code></pre>
  
  <p>There's dozens of other lines in the helper function, and it's called dozens of times in main, but these are the lines that are causing me the problem. I know that the helper function is using local scope instead of using the one from main, but my question is, why? and how do I fix it?</p>
  
  <p>I don't want to make x global, I just want the helper to use the already existing x instead of making up its own. Without this helper function, the total number of lines of code is going to quadruple, at least, and the code will be a convoluted, unreadable mess.</p>
  
  <p>EDIT: Also, Main uses x a whole bunch, so I can't just define it locally, in case that wasn't clear.</p>