I suspect you are getting "local variable referenced before assignment". If so, this is because you are using nonlocal variables and python is deciding some of your code is making that variable name local. The short story is, make the variables nonlocal explicitly using "nonlocal" function. The answer why arrays work and variables dont is that you can add elements to an array without changing the array. Here is some sample code that shows what works and what doesn't. It can behave in very non obvious ways, since "a += [3]" assigns a new array when "a.append(3)" doesn't. which has a big impact in this scenario. But use the nonlocal keyword and you will get the exact behavior you expect.
#!/usr/bin/python
def foo():
var = "a"
array = [0]
# will work
def test1():
print(var)
# will break, becase var is local, even thought assigned happens later
def test2():
print(var)
var = "b"
# works because we told python var is nonlocal
def test3():
nonlocal var
print(var)
var = "b"
# breaks because we are actually assigning the array
def test4():
print(array[0])
array += [3]
# works becase array is not local
def test5():
nonlocal array
print(array[0])
array += [3]
# works because we are not assiging the array
def test6():
print(array[0])
array.append(3)
# works becasuse we are not assigning the arry
def test7():
print(array[0])
array[0] = [3]
test7()
foo()