Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE USE PYTHONE 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 PYTHONE

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning PostgreSQL

Authors: Salahaldin Juba, Achim Vannahme, Andrey Volkov

1st Edition

178398919X, 9781783989195

Students also viewed these Databases questions

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago