So, everyone should use JS eh?!

So, everyone should use JS eh?!

Over the last couple of years I've lost track of the number of people who've told me that Python is dead because eventually everyone will be using Javascript .. because it runs on the server AND in the browser. Although I've always considered that the argument has merit, Node's stability and maturity are still a long way off this becoming reality, as are available libraries and support frameworks.

In the meantime .. what if .. we used Python everywhere, instead of Javascript?


As it turns out, there are a bunch of ways to get Python source code to run inside a browser, after a little reading I decided to give Brython a go .. it's promise of Python3 was too much to resist in the face of multiple Python 2 options.

Turns out it's almost too easy, I think I might need to spend a lot more time on it before considering it a done-deal, however a relatively short session yielded some fairly impressive results.

The repo is here; My Brython demon on Github

Essentially you need to include "brython.js" in your page, then add "brython()" to your on-load handler, and from that point on, you can include Python code simply by setting the 'type' to "text/python" instead of "text/javascript". (no seriously, not joking .. that's all ..) Consider;

<!DOCTYPE html>
<html lang="en" xmlns="">
    <meta charset="UTF-8">
    <script src="js/brython.js"></script>
    <script src="" type="text/python"></script>
<body onload="brython()">

Then in;

print('Hello From Python!')

And you're off!

There's a little more in the demo if you're interested, specifically a little with classes, inheritance and integrating with pre-existing JS libraries / modules .. looks cool tho'! :)