0

I have to read through a text file and replace all occurences of

%%CNT1%%

with the value of a counter.

The part of my code that does the actuall replacements looks like this:

for i in range(1, (count1 + 1)):
    out.writelines(re.sub("%%CNT1%%", str(i), text))

This works fine. Now what I need to do is to still replace all te occurences of %%CNT1%%, but there are places where it looks like this: A%%CNT1%%. My code does not replace %%CNT1%% with the ount value if there is an A in front of it (eg A%%CNT1%%)

Is there any way for me to fix this?

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by P00dle
0

Hehe, turns out my code was fine.

I should have double checked on my boss. Instead of putting %%CNT1%% and A%%CNT1%% in the file, the second count was A$$CNT1%%, which completely messed it all up.

Thank you for the sugestion though :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.