I have a created a variable at the start of my program, and another in a def before an important IF. However, I keep running into problems with reading & writing them.
I have the following code snippet:
#(...)
move_to = "finishedImages"
amount_moved = 0
def put_in(is_training:bool, file:Path):
pthstr = file.__str__()
target = move_to
if is_training:
target = target + "/train" # Makes a local instead!
else:
target = target + "/test" # Makes a local instead!
shutil.move(file, move_to )
shutil.move(pthstr[:len(pthstr) - 3] + "jpg", move_to)
amount_moved += 1 # Can't even read amount_moved!
#(...)
My problem is that the IF does not override the target variable but insted creates a new local one, despite the fact it can read it. In effect, these lines become useless as my program continues to use the old target value.
Furthermore, the amount_moved cannot be accessed.
I'm more used to other languages where the scope system is rather simple such as Java, help!