Skip to content Skip to sidebar Skip to footer

Python , Changing A Font Size Of A String Variable

I have a variable that gets sent to a email as text but the text is all pretty much a standard size with everything the same. I would like to add some emphasis to it as well as mak

Solution 1:

Strings don't have a font size. Strings store sequences of characters (unicode strings) or bytes to be interpreted as characters (byte strings).

Font size is an element of presentation, and is a function of whatever presentation and rendering system you are using.

As you mention an email, you could create a multipart email with an HTML part, and format it accordingly in that HTML document.


Solution 2:

If python is sending out the email through your SMTP server; You'll want to change the email type to html formatting by setting the content-type to text/html

# Build the email message
sender_name = "My script"
sender_email = "someEmail@company.com"
reciver_emails = ['receive1@company.com', 'receive2@company.com']
subject = "MY email subject"
message = "HTML <b>bolded</b> text"

email = ("From: %s <%s>\r\n"
         "To: %s\r\n" % (sender_name, sender_email, receiver_emails))

email = email + "CC: %s\r\n" % (cc_emails)
email = email + ("MIME-Version: 1.0\r\n"
                 "Content-type: text/html\r\n"
                 "Subject: %s\r\n\r\n"""
                 "<html>\r\n"
                 "%s\r\n"
                 "</html>" %  (subject, message))

You can then add html type tags as the some of the answers have stated.


Post a Comment for "Python , Changing A Font Size Of A String Variable"