I have this code:
count = -1
with open("text.txt", "r") as f:
content = f.readlines()
for line in content:
if line.startswith(" <Vertex>"):
count += 1
line = line.replace(str(line), str(" <Vertex> " + str(count) + " {\n"))
continue
else:
pass
with open("text2.txt", "w") as f:
f.writelines(content)
When it runs, it should replace any line that starts with " <Vertex>"
with " <Vertex> 0 {"
, or whatever number the count is on.
When I run it, it executes fine, but when I open the new text2.txt
file, it is the exact same as text.txt
.
What am I doing wrong?