I want to change an element in an array during a loop:
lines=open("/etc/fstab","r").readlines() for line in lines: if line.split()[1]=="/": line="# "+line
Now that does not change the contents of the array (commenting out a particular line in the file). I know you can easily make a loop counter, an d add i=i+1, but isn't there a better way?
== Answer== Try using the enumerate builtin.
lines=open("/etc/fstab","r").readlines() for index,line in enumerate(lines): if line.split()[1]=="/": lines[index] ="# "+line
When answering questions, add the CategoryAskingForHelpAnswered category when saving the page. This will move the link to this page from the questions section to the answers section on the Asking for Help page.