Replies: 5 comments 2 replies
-
Profound Apologies for the very poor formatting of my question here. I will do better next time |
Beta Was this translation helpful? Give feedback.
-
Should you expect more help, I'd strongly suggest to read about formatting your code properly. But here's how to replace values. html_template = 'start %s1 %s2 end'
print(html_template.replace('%s1', 'XXX').replace('%s2', 'YYY')) or (even easier): html_template = 'start {} {} end'
print(html_template.format('XXX', 'YYY')) |
Beta Was this translation helpful? Give feedback.
-
Hi
Thank you very much indeed for your response. I Take your point about formatting.
I will use your code asap. I know I can easily find out by trying it but just for the record, would I be right in thinking I can replace s1 and s2 with variables instead of text strings?
Sent from Outlook for iOS<https://aka.ms/o0ukef>
…________________________________
From: Norbert ***@***.***>
Sent: Saturday, November 16, 2024 1:34:13 PM
To: micropython/micropython ***@***.***>
Cc: Trevor Watson ***@***.***>; Author ***@***.***>
Subject: Re: [micropython/micropython] substituting real values for % terms in an html document on a Pico webpage server (Discussion #16251)
Should you expect more help, I'd strongly suggest to read about formatting your code properly.
But here's how to replace values.
html_template = 'start %s1 %s2 end'
print(html_template.replace('%s1', 'XXX').replace('%s2', 'YYY'))
or (even easier):
html_template = 'start {} {} end'
print(html_template.format('XXX', 'YYY'))
—
Reply to this email directly, view it on GitHub<#16251 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AXQTANAB2QWZ2ARGMBPWVR32A5CVLAVCNFSM6AAAAABR3JJXRSVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTCMRXG42TSMA>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
You can use any kind of object. If an object has a The Or you could use https://github.com/pfalcon/utemplate |
Beta Was this translation helpful? Give feedback.
-
Hi
Thank you very much indeed for responding. I’ll try these out and hope to have some feedback soon.
Sent from Outlook for iOS<https://aka.ms/o0ukef>
…________________________________
From: Andre Müller ***@***.***>
Sent: Monday, November 18, 2024 9:57:07 AM
To: micropython/micropython ***@***.***>
Cc: Trevor Watson ***@***.***>; Author ***@***.***>
Subject: Re: [micropython/micropython] substituting real values for % terms in an html document on a Pico webpage server (Discussion #16251)
You can use any kind of object. If an object has a __str__ method, the output of this method is used to fill in the text. If the object has not a __str__ method, you'll get the representation of an object (__repr__).
The % format method should not be used for formatting. It's still available for compatibility reasons.
Use instead format strings to substitute strings.
Or you could use https://github.com/pfalcon/utemplate
—
Reply to this email directly, view it on GitHub<#16251 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AXQTANH7L76ITVQDF4HXR632BG2XHAVCNFSM6AAAAABR3JJXRSVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTCMRZGAYDENY>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
This is my html code
create the html document template
html = """
<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;} .buttonGreen { background-color: #4CAF50; border: 2px solid #000000;; color: white; padding: 15px 32px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer; } .buttonRed { background-color: #D11D53; border: 2px solid #000000;; color: white; padding: 15px 32px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer; } text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;} </style>Control Panel
LED ON
LED OFF
%s1
%s2
""" This is my Tonny micropython server code s1 = LEDState\ + " and " + buttonState\ + " and internal temp is " + PicoTemp\ + " with distance " + str(distance)\ + " dated "\ + str(MyTime[0:3]) s2 = "second element" s1 = LEDState + " and " + buttonState response = html % s1 % s2 ********************************************this line throws the syntax error cl.send('HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n') cl.send(response)
How do I get new values for both s1 and s2 into the html doc ?? help please
Beta Was this translation helpful? Give feedback.
All reactions