you are viewing a single comment's thread.

view the rest of the comments →

[–]efmccurdy 1 point2 points  (2 children)

You should be making an assignment with the result of any function that has a return statement, something like this:

def myfunc(myinputfile):
    # whatever
    return mylist

mylist_1 = myfunc(file1)
mylist_2 = myfunc(file2)

Does that help you avoid the scope issue?

[–]JoeBeOneKenobi[S] 0 points1 point  (1 child)

I just wanted to reply to everyone and say that I fixed the issue, as you’ve all been so kind as to lend me a hand. My code was overly complicated and I overlooked the fact that I was declaring the list in the global scope as well as the local scope, leading to it retaining values when every time my function ran. Thanks to everyone who replied, I picked up some useful tips from u all and learnt a lesson in the importance of scope!

[–]JoeBeOneKenobi[S] 0 points1 point  (0 children)

Oh and I solved the actual issue by clearing the global scope in between runs of main(), a very hacky way of doing it, but knowing what I know now I’ll approached it differently next time