Binding frustration
JCM
joshway_without_spam at myway.com
Thu Sep 18 18:12:22 EDT 2003
Rob Hunter <rob at cs.brown.edu> wrote:
...
> def getGenres(title): #it takes a movie title and returns a list of
> genres that the movie falls into
> result = [] # my accumulator
> def inGenre(g): # g is a genre
> if <here I test if "title" is of genre g (using a simple Python
> dictionary I have collected from a mini web crawl)>:
> result = result + [g] # if title is of genre g, then add
Here you're attempting to rebind a variable which lives in an
enclosing scope. This isn't possible in Python (except for globals).
Use result.append(g) instead and it should work.
More information about the Python-list
mailing list