I'm creating a Python script to create a HTML document with the message containing HTML code in triple quotes. How would I go about formatting some of the text inside the triple quote?
I figured it out with a simple solution.
I exit the triple quotes with triple quotes then added my variables by using + "{}".format(row[0]) + then re adding triple quotes to continue the string.
a and b would be inputs from your cursor???
Sorry, but maybe Joe Borgione might have had to do email notification or knows someone that does
a <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Hey folks..."</SPAN> b <SPAN class="operator token">=</SPAN> <SPAN class="string token"><SPAN>"\n</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2Fwww.python.org" target="_blank">http://www.python.org</A><SPAN>"</SPAN></SPAN> t <SPAN class="operator token">=</SPAN> <SPAN class="string token">"{}\nHow are you?\nHere is the link you wanted:{}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>a<SPAN class="punctuation token">,</SPAN> b<SPAN class="punctuation token">)</SPAN> h <SPAN class="operator token">=</SPAN> <SPAN class="string token">"""\ <html> <head></head> <body> <p>{} How are you?<br> Here is the link you wanted. {} </p> </body> </html> """</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>a<SPAN class="punctuation token">,</SPAN> b<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"{}\n{}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>t<SPAN class="punctuation token">,</SPAN> h<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> Hey folks<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> How are you? Here <SPAN class="keyword token">is</SPAN> the link you wanted<SPAN class="punctuation token">:</SPAN> http<SPAN class="punctuation token">:</SPAN><SPAN class="operator token">//</SPAN>www<SPAN class="punctuation token">.</SPAN>python<SPAN class="punctuation token">.</SPAN>org <SPAN class="operator token"><</SPAN>html<SPAN class="operator token">></SPAN> <SPAN class="operator token"><</SPAN>head<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>head<SPAN class="operator token">></SPAN> <SPAN class="operator token"><</SPAN>body<SPAN class="operator token">></SPAN> <SPAN class="operator token"><</SPAN>p<SPAN class="operator token">></SPAN>Hey folks<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> How are you?<SPAN class="operator token"><</SPAN>br<SPAN class="operator token">></SPAN> Here <SPAN class="keyword token">is</SPAN> the link you wanted<SPAN class="punctuation token">.</SPAN> http<SPAN class="punctuation token">:</SPAN><SPAN class="operator token">//</SPAN>www<SPAN class="punctuation token">.</SPAN>python<SPAN class="punctuation token">.</SPAN>org <SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>p<SPAN class="operator token">></SPAN> <SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>body<SPAN class="operator token">></SPAN> <SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>html<SPAN class="operator token">></SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
I'm really just looking to have an email composed based on a fields from a search cursor using python but I want to be able to send it manually.
perhaps you will have to google, …. html email python
I don't think it is just the triple quotes
For example
Sending HTML email using Python - Stack Overflow
I tested your suggestions and it still just produces {} in the body of the email.
did you try some of the suggestions for formatting within the triple quote?
What did your code produce
In the Python script below I'm creating an HTML document with a hyperlink to generate an email. How would I use formatting .format(row[0]) in the body section of the email?
<SPAN class="keyword token">import</SPAN> arcpy<SPAN class="punctuation token">,</SPAN> datetime<SPAN class="punctuation token">,</SPAN> os arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN> points <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"***********"</SPAN> today <SPAN class="operator token">=</SPAN> datetime<SPAN class="punctuation token">.</SPAN>date<SPAN class="punctuation token">.</SPAN>today<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> dte <SPAN class="operator token">=</SPAN> today<SPAN class="punctuation token">.</SPAN>strftime<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'%m/%d/%Y'</SPAN><SPAN class="punctuation token">)</SPAN> dtep <SPAN class="operator token">=</SPAN> today<SPAN class="punctuation token">.</SPAN>strftime<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'%m%d%Y'</SPAN><SPAN class="punctuation token">)</SPAN> fields <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'Applicant'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Date_Final'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Email'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Permit_No'</SPAN><SPAN class="punctuation token">]</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>MakeFeatureLayer_management<SPAN class="punctuation token">(</SPAN>points<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'FinalizedApproaches'</SPAN><SPAN class="punctuation token">)</SPAN> f<SPAN class="operator token">=</SPAN> open<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Finalized_{}.html"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>dtep<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"w+"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>points<SPAN class="punctuation token">,</SPAN> fields<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Date_Final = CURRENT_DATE"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> cursor<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> cursor<SPAN class="punctuation token">:</SPAN> message <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN>"<SPAN class="operator token"><</SPAN>!DOCTYPE html<SPAN class="operator token">></SPAN> <SPAN class="operator token"><</SPAN>html<SPAN class="operator token">></SPAN> <SPAN class="operator token"><</SPAN>head<SPAN class="operator token">></SPAN> <SPAN class="operator token"><</SPAN>style<SPAN class="operator token">></SPAN> table <SPAN class="punctuation token">{</SPAN> font<SPAN class="operator token">-</SPAN>family<SPAN class="punctuation token">:</SPAN> arial<SPAN class="punctuation token">,</SPAN> sans<SPAN class="operator token">-</SPAN>serif<SPAN class="punctuation token">;</SPAN> border<SPAN class="operator token">-</SPAN>collapse<SPAN class="punctuation token">:</SPAN> collapse<SPAN class="punctuation token">;</SPAN> width<SPAN class="punctuation token">:</SPAN> <SPAN class="number token">100</SPAN><SPAN class="operator token">%</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> td<SPAN class="punctuation token">,</SPAN> th <SPAN class="punctuation token">{</SPAN> border<SPAN class="punctuation token">:</SPAN> 1px solid <SPAN class="comment token">#dddddd;</SPAN> text<SPAN class="operator token">-</SPAN>align<SPAN class="punctuation token">:</SPAN> left<SPAN class="punctuation token">;</SPAN> padding<SPAN class="punctuation token">:</SPAN> 8px<SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> tr<SPAN class="punctuation token">:</SPAN>nth<SPAN class="operator token">-</SPAN>child<SPAN class="punctuation token">(</SPAN>even<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> background<SPAN class="operator token">-</SPAN>color<SPAN class="punctuation token">:</SPAN> <SPAN class="comment token">#dddddd;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>style<SPAN class="operator token">></SPAN> <SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>head<SPAN class="operator token">></SPAN> <SPAN class="operator token"><</SPAN>body<SPAN class="operator token">></SPAN> <SPAN class="operator token"><</SPAN>h2<SPAN class="operator token">></SPAN>Notification Report<SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>h2<SPAN class="operator token">></SPAN> <SPAN class="operator token"><</SPAN>table<SPAN class="operator token">></SPAN> <SPAN class="operator token"><</SPAN>tr<SPAN class="operator token">></SPAN> <SPAN class="operator token"><</SPAN>th<SPAN class="operator token">></SPAN>Customer<SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>th<SPAN class="operator token">></SPAN> <SPAN class="operator token"><</SPAN>th<SPAN class="operator token">></SPAN>Status<SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>th<SPAN class="operator token">></SPAN> <SPAN class="operator token"><</SPAN>th<SPAN class="operator token">></SPAN>Date<SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>th<SPAN class="operator token">></SPAN> <SPAN class="operator token"><</SPAN>th<SPAN class="operator token">></SPAN>Email<SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>th<SPAN class="operator token">></SPAN> <SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>tr<SPAN class="operator token">></SPAN> <SPAN class="operator token"><</SPAN>tr<SPAN class="operator token">></SPAN> <SPAN class="operator token"><</SPAN>td<SPAN class="operator token">></SPAN>Test Name<SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>td<SPAN class="operator token">></SPAN> <SPAN class="operator token"><</SPAN>td<SPAN class="operator token">></SPAN>Finalized<SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>td<SPAN class="operator token">></SPAN> <SPAN class="operator token"><</SPAN>td<SPAN class="operator token">></SPAN><SPAN class="number token">08</SPAN><SPAN class="operator token">/</SPAN><SPAN class="number token">30</SPAN><SPAN class="operator token">/</SPAN><SPAN class="number token">2018</SPAN><SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>td<SPAN class="operator token">></SPAN> <SPAN class="operator token"><</SPAN>td<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN>a href<SPAN class="operator token">=</SPAN><SPAN class="string token"><SPAN>"mailto:</SPAN><A class="jive-link-email-small" href="mailto:test@email.com" rel="nofollow noopener noreferrer" target="_blank">test@email.com</A><SPAN>&subject=Permit Status: Finalized&body={}"</SPAN></SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="operator token">%</SPAN><SPAN class="number token">0D</SPAN><SPAN class="operator token">%</SPAN>0AThis <SPAN class="keyword token">is</SPAN> to notify you that your approach has been finalized<SPAN class="punctuation token">.</SPAN> Please use the link below to view your permit documentation<SPAN class="punctuation token">.</SPAN><SPAN class="operator token">%</SPAN><SPAN class="number token">0D</SPAN><SPAN class="operator token">%</SPAN><SPAN class="number token">0A</SPAN><SPAN class="operator token">%</SPAN><SPAN class="number token">0D</SPAN><SPAN class="operator token">%</SPAN>0Ahttps<SPAN class="punctuation token">:</SPAN><SPAN class="operator token">//</SPAN>www<SPAN class="punctuation token">.</SPAN>arcgis<SPAN class="punctuation token">.</SPAN>com"<SPAN class="operator token">></SPAN>Notify<SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>a<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN><SPAN class="operator token">></SPAN> <SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>tr<SPAN class="operator token">></SPAN> <SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>table<SPAN class="operator token">></SPAN> <SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>body<SPAN class="operator token">></SPAN> <SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>html<SPAN class="operator token">></SPAN><SPAN class="string token">""</SPAN>" f<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN>message<SPAN class="punctuation token">)</SPAN> f<SPAN class="punctuation token">.</SPAN>close<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"{} Finalized report generate"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>dte<SPAN class="punctuation token">)</SPAN> <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
but if you want to keep the triple quotes then you have to single quote the triple quotes so that they appear but not affect the escaped quotes…
a <SPAN class="operator token">=</SPAN> <SPAN class="string token">'""" \'hello\' said "the \"parrot\" """'</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>a<SPAN class="punctuation token">)</SPAN> <SPAN class="string token">""" 'hello' said "the "parrot" """</SPAN> a Out<SPAN class="punctuation token">[</SPAN><SPAN class="number token">8</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'""" \'hello\' said "the "parrot" """'</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
simple ehh???
mess with single and double quotes and escaping... at least in python 3
a <SPAN class="operator token">=</SPAN> <SPAN class="string token">""" \'hello\' said "the \"parrot\" """</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>a<SPAN class="punctuation token">)</SPAN> <SPAN class="string token">'hello'</SPAN> said <SPAN class="string token">"the "</SPAN>parrot" a <SPAN class="string token">' \'hello\' said "the "parrot" '</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.