In [1]:
abbr = 'NLP'
full_text = 'Natural Language Processing'
# Enter your code here:
print(f'{abbr} stands for {full_text}')
In [6]:
%%writefile contacts.txt
First_Name Last_Name, Title, Extension, Email
In [3]:
# Write your code here:
with open('contacts.txt') as c:
fields = c.read()
# Run fields to see the contents of contacts.txt:
fields
Out[3]:
In [4]:
# Perform import
import PyPDF2
# Open the file as a binary object
f = open('Business_Proposal.pdf','rb')
# Use PyPDF2 to read the text of the file
pdf_reader = PyPDF2.PdfFileReader(f)
# Get the text from page 2 (CHALLENGE: Do this in one step!)
page_two_text = pdf_reader.getPage(1).extractText()
# Close the file
f.close()
# Print the contents of page_two_text
print(page_two_text)
In [5]:
# Simple Solution:
with open('contacts.txt','a+') as c:
c.write(page_two_text)
c.seek(0)
print(c.read())
In [7]:
# CHALLENGE Solution (re-run the %%writefile cell above to obtain an unmodified contacts.txt file):
with open('contacts.txt','a+') as c:
c.write(page_two_text[8:])
c.seek(0)
print(c.read())
In [8]:
import re
# Enter your regex pattern here. This may take several tries!
pattern = r'\w+@\w+.\w{3}'
re.findall(pattern, page_two_text)
Out[8]: