Puzzle 6 Spam, Spam, Spam
Python Brain Teasers — by Miki Tebeka (15 / 40)
👈 Send It to the Printer | TOC | User! Identify Yourself 👉
from email.message import EmailMessage
msg = EmailMessage()
msg['From'] = 'prince@palace.ng'
msg['To'] = 'Scrooge McDuck <scoorge@disney.com>'
msg.set_content('''\
Dear Sir.
I'm a Nigerian prince who came into some misfortune.
...
''')
print(msg)
Guess the Output
IMPORTANT
Try to guess what the output is before moving to the next page.
This code will raise a ModuleNotFoundError exception.
When Python looks for a module to import (e.g., email), it’ll go over the directories in sys.path and try to find a module matching the name. The first value in sys.path is ” (the empty string). ” stands for the current directory, and in the current directory you have the teaser file email.py. Python will load this email.py instead of the one in the standard library and will not find the message submodule in it.