I had a similar issue: I wanted my triple quoted string to be indented, but I didn't want the string to have all those spaces at the beginning of each line. I used re
to correct my issue:
print(re.sub('\n *','\n', f"""Content-Type: multipart/mixed; boundary="===============9004758485092194316=="
` MIME-Version: 1.0
Subject: Get the reader's attention here!
To: recipient@email.com
--===============9004758485092194316==
Content-Type: text/html; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Very important message goes here - you can even use <b>HTML</b>.
--===============9004758485092194316==--
"""))
Above, I was able to keep my code indented, but the string was left trimmed essentially. All spaces at the beginning of each line were deleted. This was important since any spaces in front of the SMTP or MIME specific lines would break the email message.
The tradeoff I made was that I left the Content-Type
on the first line because the regex
I was using didn't remove the initial \n
(which broke email). If it bothered me enough, I guess I could have added an lstrip like this:
print(re.sub('\n *','\n', f"""
Content-Type: ...
""").lstrip()
After reading this 10 year old page, I decided to stick with re.sub
since I didn't truly understand all the nuances of textwrap
and inspect
.