[Solved] replace the same occurring number with another random number [closed]


I didn’t really get what you mean, but if you want to replace a specific text in your file with a random integer then try:

import fileinput
from random import randint
with fileinput.FileInput(fileToSearch, inplace=True, backup='.bak') as file:
    for line in file:
        print(line.replace(textToSearch, textToReplace), end='')

with textToReplace = randint(1990, 2020)

Hope that helps

7

solved replace the same occurring number with another random number [closed]