Question: Read a file to string in Python: # !/usr/bin/env python # -*- coding: utf-8 -*- import os def read_file(input_file): with open (input_file) as f: file_content

Read a file to string in Python:

#!/usr/bin/env python # -*- coding: utf-8 -*- import os def read_file(input_file): with open(input_file) as f: file_content = f.read().strip(os.linesep) return file_content def main(): read_file('youfile.txt') if __name__ == '__main__': main() 

Implement a function convertYouToI(input_file) that read in the 'youfile.txt' file, count how many 'you' in the file, change the word 'you' to 'I' and output the file to a new file called 'correctFile.txt' with the number of 'you' at the end of the file.

>>> input_file = 'youfile.txt' >>> convertYouToI(input_file) If I can keep your head when all about I are losing theirs and blaming it on I If I can trust yourself when all men doubt I but make allowance for their doubting too If I can wait and not be tired by waiting or being lied about don't deal in lies or being hated don't give way to hating and yet don't look too good nor talk too wise.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!