Search-and-delete text processing problem...

M.E.Farmer mefjr75 at hotmail.com
Fri Apr 1 21:45:29 EST 2005


My apologies you did indeed use writelines correctly ;)
dohhh!
I had a gut reaction to this.
Py>f = ['hij\n','efg\n','abc\n']
Py> for i in f:
...     if i.startswith('a'):
...         i == ''
Py> f
['hij\n', 'efg\n', 'abc\n']
Notice that it does not modify the list in any way.
You are trying to loop thru the list and modify the items in place, it
just won't work.
When you rebind the item name to a new value ' ' it does not rebind the
element in the list just the current item.
It is also bug prone to modify a list you are looping over.
M.E.Farmer




More information about the Python-list mailing list