I am trying to search through a jsp file, see if it contains a certain tag, and replace an attribute on the same line if the tag exists on the same line.
For example <c:out var="taskToRedirect" property="dueDate"
I am trying to see if the line contains <c:out and if it does, I need to change the "property" attribute to "value", and only on that line, I don't want to change all of the "property" attributes in the entire file.
Currently what I have is:
f = open(filepath) c = f.read() for i in c: if ("<c:out" in i): c=c.replace(i,i.replace("property","value")) f.write(c) f.close() The code appears to do nothing, and throws no run time errors, c is the string representation of the contents of a file, and i is the current line in the file. Any suggestions are welcome.
ca list of the lines in the file?cis the contents of the file. i is an individual line in the file.