0

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.

CS2016
  • 331
  • 1
  • 3
  • 15

1 Answers1

0

I don't see where you write the output. The file doesn't change unless you write out those changes. c is only your internal copy.

Have you traced whether c changes as expected? Have you tried this with a small file?

Prune
  • 76,765
  • 14
  • 60
  • 81