altering an object as you iterate over it?

John Salerno johnjsal at NOSPAMgmail.com
Fri May 19 16:22:14 EDT 2006


Paul McGuire wrote:

> Your coding style is a little dated - are you using an old version of
> Python?  This style is the old-fashioned way:

I'm sure it has more to do with the fact that I'm new to Python, but 
what is old-fashioned about open()? Does file() do anything different? I 
know they are synonymous, but I like open because it seems like it's 
more self-describing than 'file'.

> Now to your question about why '\n' lines persist into your new list.  The
> answer is - you are STILL UPDATING THE LIST YOUR ARE ITERATING OVER!!!

Doh! I see that now! :)


> You might also want to strip whitespace from your lines

Another good hint. Thanks for the reply!



More information about the Python-list mailing list