[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Subtle Memory Bug




--- Kris Schnee <kschnee@xxxxxxxxxx> wrote:
> So, like this?
> 
> foo = [<instance>, <instance>, etc.]
> n = 0
> while n < len(foo):
>      foo[n].DoStuff() ## Might result in deleting
> foo[n]
>      n += 1
> 
> I think I've done something like that before, but I
> don't remember 
> whether len(foo) gets evaluated anew each time.

I don't remember either, but in this particular
situation you can structure the loop so that it
doesn't matter. Set n to len(foo) and count downwards
to 0. Items that are deleted will be "behind" your
count now.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com