Question: In Python,write a function that opens the file 'weblog.txt' and stores the entire contents of the file inside a string. (We can do this because
In Python,write a function that opens the file 'weblog.txt' and stores the entire contents of the file inside a string. (We can do this because the file is not tremendously large. If the file was huge, we should probably not store all of the text of the file inside a variable since that would eat up too much memory). Then ask the user to enter a string of text. Search for that text inside the file (i.e. the string you created above). Your function should output how many times the user's search string was present inside the file. Search for something like Status 401 which is an error that a web server log says to indicate that it couldn't find the resource the user was asking for. You should get back a value of 10.
NOTE: If, when you open the file, you get an error that says something about UnicodeDecodeError, modify your open() function so that it includes an additional 'encoding' argument: open(the_file_name,'r', encoding='latin1')
search Log Enter text to search for Status 401 10 search Log Enter text to search for Status 200 40 search Log Enter text to search for 64.242.88.10 47Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
