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?

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 :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.