python newbie - question about lexical scoping

Matt Barnicle mattb at wageslavery.org
Sat Dec 1 00:47:44 EST 2007


hi everyone..  i've been chugging along learning python for a few months 
now and getting answers to all needed questions on my own, but this one 
i can't figure out nor can i find information on the internet about it, 
possibly because i don't understand the right words to type into google..

i have a very common scenario and need to know the python way to do it.  
take this example loop:

comments = []
for row in rows:
    comment = models.comment()
    comment.author = row[1]
    comment.text = row[0]
    comments.append(comment)

the problem is that when i go to retrieve the comments later, they are 
all the same object!  i assume this is due to there being no lexical 
scoping?  so what is the solution to this?

thank u all!

- m@



More information about the Python-list mailing list