I am replacing the '2010' with a random number:
from random import randint
with open("data.json", "rt") as fin:
with open("dataout.json", "wt") as fout:
for line in fin:
fout.write(line.replace('2010', str(randint(1990, 2007))))
how can I replace two items in one code, that is:
fout.write(line.replace('2099', str(randint(1800, 1900))))
fout.write(line.replace('2010', str(randint(1990, 2007))))
Use two replace()
method:
from random import randint
with open("data.json", "rt") as fin:
with open("dataout.json", "wt") as fout:
for line in fin:
fout.write(line.replace('2010', str(randint(1990, 2007))).replace('2099', str(randint(1800, 1900))))
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments