Restrictions • You're not allowed to make more than one pass reading a file • You’re not allowed to modify the input file in any way • The only functions you're allowed to use are: open, close, read, write, readline, range, len, append, next, split, strip, join
2. Text replacement Write a function replace_text that takes three parameters, a file name and two strings (not words!), and creates a new file named output.txt that is a copy of the input file where every occurrence of the second parameter has been replaced by the third parameter.
Please comment below for any queries...
Please don't forget to upvote if the answer is helpful thanks..
Executable
Code:
def replace_text(inFile, firstString, secondString):
lines = open(inFile).read()
writer = open('output.txt', 'w')
l=secondString.join(lines.split(firstString))
writer.write(l)
writer.close()
#Sample Output:
replace_text('input.txt', 'Baa, Baa, Black Sheep' , 'Bee, Bee, White Sheep')
input.txt

output.txt after executing :
Restrictions • You're not allowed to make more than one pass reading a file • You’re...