Welcome folks today in this blog post we will be running python
program or code in browser
using brython
library. All the full source code of the application is shown below.
Get Started
In order to get started you need to create an index.html
file inside the browser and copy paste the below code
index.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<html> <head> <meta charset="utf-8"> <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/brython@3.11.0/brython.min.js"> </script> <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/brython@3.11.0/brython_stdlib.js"> </script> </head> <body onload="brython()"> <script type="text/python"> from browser import document document <= "Hello World !" </script> </body> </html> |
As you can see we are importing the brython
library cdn inside the browser and then we are simply printing out something
inside the browser. For that we are calling the brython()
function inside the onload
attribute of body. And then we are writing hello world to the document