Hello everybody,
I have a text-file with multiple strings which I want to be replaced by an increasing number.
For example there is there the string "example" 7 times in it and I want to replace "example" with a number:
Before:
This example is an example on how to make an example with the word example. the example ends here with an example. for example.
After
This 1 is an 2 on how to make an 3 with the word 4. the 5 ends here with an 6. for 7.
How do you do that?
Also, while developing the script, I want it to look for every text-file inside my folder not just a specified file (see code below).
This is what I have now but it doens't work:
I have a text-file with multiple strings which I want to be replaced by an increasing number.
For example there is there the string "example" 7 times in it and I want to replace "example" with a number:
Before:
This example is an example on how to make an example with the word example. the example ends here with an example. for example.
After
This 1 is an 2 on how to make an 3 with the word 4. the 5 ends here with an 6. for 7.
How do you do that?
Also, while developing the script, I want it to look for every text-file inside my folder not just a specified file (see code below).
This is what I have now but it doens't work:
#!/usr/bin/env python3 fileCounter = 1 with open('*.txt', 'r') as file : filedata = file.read() filedata = filedata.replace('example', ''+fileCounter) with open('*.txt', 'w') as file: file.write(filedata)