python - Invalid syntax. I save my text file on my desktop calling it file. -
create graph:-
def loadgraphfile(file): graph = [] line in file: contents = line.split() moviename = contents[0] actornames = [contents[i]+ " " + contents[i+1] in range(1, len(contents), 2)] movienode = findnode(graph, moviename) if movienode == none: movienode = mknode(moviename) graph.append(movienode) actorname in actornames: actornode = findnode(graph,actorname) if actornode == none: actornode = mknode(actorname) graph.append(actornode) actornode.neighbor.append(movienode) movienode.neighbor.append(actornode) return graph def loadgraphfilename('file.text'): return loadgraphfile(open('file.text'))
you declared function wrong:
def loadgraphfilename('file.text'): # change return loadgraphfile(open('file.text'))
to this:
def loadgraphfilename(): # don't use anyway return loadgraphfile(open('file.text'))
or:
def loadgraphfilename(filename='file.text'): # file.text default. if give parameter it, filename change parameter return loadgraphfile(open(filename)) # , use here
Comments
Post a Comment