email.message_from_string
Prev: email.message_from_file | Up: email
Rel: email.message_from_binary_file, email.message_from_bytes, email.message_from_file
Ref: docs.python.org — email.message_from_string
Tags: #public #python3 #stdlib #email
Import
import email
from email import message_from_string
Signature & Overview
email.message_from_string(s, *args, **kws)
Parse a string into a Message object model.
Usage
import email
from email import policy
msg = email.message_from_string("From: ada@example.com\nSubject: Hello\n\nBody", policy=policy.default)
assert msg["From"] == "ada@example.com"
Gotchas
- Pass
policy=email.policy.defaultto get modern header decoding and.get_content().
REPL Inspect
from email import message_from_string
help(message_from_string)
Linked from
Related notes
- tuts/python3/stdlib_module/email/message_from_binary_file Linked here; links to this page; shared tags: #email, #stdlib
- tuts/python3/stdlib_module/email/message_from_bytes Linked here; links to this page; shared tags: #email, #stdlib
- tuts/python3/stdlib_module/email/message_from_file Linked here; links to this page; shared tags: #email, #stdlib
- tuts/python3/stdlib_module/email Linked here; links to this page; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib
- tuts/c/stdlib/assert/static_assert shared tags: #stdlib
- tuts/c/stdlib/ctype shared tags: #stdlib
- tuts/c/stdlib/ctype/isalpha shared tags: #stdlib