Question: PLEASE USE PYTHON fhand = open('mbox2.txt') inp = fhand.read() print ('This file contains', len(inp), 'characters ') fhand.close() fhand = open('mbox2.txt') for line in fhand: line

PLEASE USE PYTHON

fhand = open('mbox2.txt')

inp = fhand.read()

print ('This file contains', len(inp), 'characters ')

fhand.close()

fhand = open('mbox2.txt')

for line in fhand:

line = line.rstrip() # Remove the newline character, creates blank lines

if line.startswith('From:'):

print (line[6:]) # Strip away From:

Isolating and extracting file data

Starting with the code to collect the e-mail addresses from mbox2.txt shown above

Add try-except to protect your application from unopened or unopenable files

Modify the code shown above to extract and print out only the name portion of all e-mail addresses beginning with From: (including the colon), not From (without a colon)

You should also write the extracted data to a file called addr.txt

It then opens, reads, and prints the contents of addr.txt to the screen

Files should be closed when they are no longer being used

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!