Can Python functions run in html as javascript does?


It is not possible to run Python in any modern browser because none contain a python interpreter. Javascript is the only language which runs in a browser without plugins like Flash or ActiveX.

One way to write Python code that will run in the browser is to use a "transpiler". This is a tool that will compile the python code into Javascript. So the browser is ultimately running the language it knows, but you're writing Python. There are already a number of languages like CoffeeScript, TypeScript and even React JSX templates that compile down to raw javascript.

An example of a Python to Javascript transpiler is Transcript. We must note that since it's not actually Python, there are no guarantees for performance or compatibility since that's largely up to how well the transpiler does it's conversion. We may start with a 3 line Python script that compiles into 30 odd lines of javascript in order to replicate what we are trying to do.

Updated on: 30-Jul-2019

149 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements