Python to javascript

 

Python code


Option:


This tool allows to convert Python to javascript online. You can get the js code (ES6 or ES5) corresponding to your Python code.

You can see the user guide to help you.

User guide

How to convert Python code to Javascript:

  • Fill in the editor above with your Python code. You can Drag and drop your file, copy and paste your code, or type directly into the editor above.
  • Choose the ECMAScript version (In "option" section) between ES6 (All modern browsers support it) and ES5.
  • Click on "Convert" button to execute the conversion of your source code.
  • You can get your js source code by clicking on the "Download file" or "Copy to clipboard" buttons.


Python to javascript compiler

This tool allows you to convert your python source code into javascript code. For this conversion it uses JavaScripthon, a Python 3 to ES6 JavaScript translator. And it uses Babel to convert ES6 to ES5, it is a JavaScript compiler.

JavaScripthon is a simple Python 3.5+ translator to JavaScript. It aims to be able to translate most of the Python's core semantics without providing a full python-in-js environment.
JavaScripthon does not handle everything yet, current todo list (As of this writing):

  • refactor the comprehensions conversion to use the snippets facility
  • refactor snippets rendering to write them as a module and import them in the module when tree conversion is enabled
  • convert dict() calls to ES6 Map object creation
  • convert set literals to ES6 Set objects. Also, update "foo in bar" to use bar.has(foo) for sets

If you choose es5, then it uses babel to convert es6 code to es5.

Why convert Python code to Javascript ? As many developers develop in Python, we may have snippets of Python code that we would like to run in a browser or on the server side via nodejs. It can also be useful for those who do not know python better than javascript. This allows for example to see the code corresponding to certain instructions in python.
If you find other reasons to do this type of code conversion, you can let me know in a comment (I am curious).

If you find a bug or think of interesting options, please indicate it in a comment.


You can report a bug or give feedback by adding a comment (below) or by clicking "Contact me" link (at the top right hand corner of the page).

Comments




a-2022-02-15 20:26
Cannot convert classmethods