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?
Apparently, python thinks I'm wrong.
So, here's a boiled-down version of my problem
def main():
x = 10
def helper(n):
if (x > n):
x -= n
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?
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.
EDIT: Also, Main uses x a whole bunch, so I can't just define it locally, in case that wasn't clear.
UnboundLocalErrorperhaps?xas a parameter tohelper()...x(e.g. expecting x to be mutated inside the function but passing in an immutable object...)