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.

2
  • Is c a list of the lines in the file? Commented Mar 10, 2017 at 19:33
  • c is the contents of the file. i is an individual line in the file. Commented Mar 10, 2017 at 20:15

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.