I'm having trouble with a recursive function I'm trying to write. It looks like the function just isn't descending. I'm not getting any errors or anything, so I don't really get what's going on. The only output I get out of it are some empty lists. Essentially I'm trying to keep track of all the paths that my program can take through some given input, and return a list holding all those paths. I'm really, really, really new to python, so there's a lot I don't know. I'm also really new to stackoverflow, so forgive the formatting errors. Thanks in advance!
def Process ( fst, input, start_state, current_path=[], input_index=0 ):
current_line = input.replace('"', '')
current_state = start_state
probability = 1
result = []
state_paths = []
this_path = current_path
paths_found = []
epsilon_paths_found = []
temp_list = []
index = input_index
if not index < len( current_line ):
return this_path
item = current_line[index]
if not item.isspace():
for edge in fst.transitions[current_state]:
next_state = current_state
if item == edge.input:
paths_found.append( edge )
index += 1
for x in paths_found:
temp_list = this_path
temp_list.append( x )
temp_entry = Process( fst, input, x.target_state, temp_list, index )
state_paths.append( temp_entry )
#epsilon returns a list
epsilon = EpsilonStates( fst.transitions[current_state] )
if epsilon:
index -= 1
for i in epsilon:
epsilon_paths_found.append( i )
for y in epsilon_paths_found:
temp_list = this_path
temp_list.append( y )
state_paths.append( Process( fst, input, y.target_state, temp_list, index ) )
return state_paths
Processends and the top-level module code begins—and that's crucial to answering your question. - abarnertIndentationErrorbefore it can even run anything… - abarnertprint locals()as the first line of Process. I see that you are using a mutable data type (list) as a default argument - that can definitely cause problems. Try a google search for "python mutable default arguments". http://effbot.org/zone/default-values.htm - wwiireturnat the end is dedented to the same level as thedef. But I have no idea if that's the only place that your post is different from your real code. It's up to you to post something that we can read, run, and debug, not for us to try to guess what your real code looks like. - abarnert