Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started