Today I learned about PyScript, a tool that lets you run Python in your HTML!
The Python 🐍 problem-solving bootcamp is starting soon. Join the second cohort now!
Today I learned about PyScript, a tool that lets you run Python from within your HTML!
I got so excited when I found out about this tool (which was presented to the world today, if I am not mistaken!) that I had to give it a try right away!
For example, you opened this page, it loaded, and then it inserted a timestamp here:
(If the timestamp doesn't show right away, wait a couple of seconds. If it still doesn't show, take into account that the PyScript version I am using here has only been tested on Chrome.)
This timestamp, which corresponds roughly to when the page finished loading, was put there by Python. I just had to write some code in the HTML of this page:
<py-script> import datetime output = Element("py-script-target") now = format(datetime.datetime.now(), "%H:%M, %A, %d %B %Y.") output.write(now) </py-script>
output = Element("py-script-target") assigns a
<span> tag I have in the source of the page to the variable
Then, I use standard Python to format the current date (
datetime.datetime.now()) into a format I like.
Finally, I write that string to the
<span> element from before!
I am very excited to see what people build with this tool! Just bear in mind that it is still in its early stages of development.
By the way, I found out about PyScript from a tweet:
That's it for now! Stay tuned and I'll see you around!
I write about Python every week. Join +16.000 others who are taking their Python 🐍 skills to the next level 🚀, one email at a time.