I am trying to pass an integer to a function. I think it might not be working because I am calling it to many times? For example I create a 2d matrix in one function called Alist and then return it. With a second function I pass Alist and specify a location for the value I want from Alist which I then return. Finally (so far), a third function will ask for the returned value and Alist. Alist is printing fine but the returned value (node) is printing 0 when it should be 4. I guess that it is using the node = 0 variable declared at the top of the code but I am not sure why.
The first line of network.txt looks like this: 0,2,4,1,6,0,
Alist = []
node = 0
file = ("F:/media/KINGSTON/Networking/network.txt")
def create_matrix(file):
with open('network.txt') as f:
Alist = []
for line in f:
part = []
for x in line.split(','):
part.append(int(x))
Alist.append(part)
return Alist
def start_node(Alist):
node = Alist[0][2]
print (node)
return node
#test neighbours to see if they can be used
def check_neighbours(node, Alist):
print (Alist)
print (node)
#check for neighbours. if we start at [0][0] we must look for [0][1]
#and [1][0]. Figure out how to add 1 to each cell to navigate across.
#running of code begins here
Alist = create_matrix(file)
start_node(Alist)
check_neighbours(node, Alist)
nodethat gets set instart_nodeisn't the global. It is getting returned, but unless the caller is doing something likenode = start_node(Alist)to set the global, the global isn't going to change, so the value will still be 0.