Python to JavaScript Converter

I want to convert some basic snippets to JavaScript, just pure Python wrote itself pure JavaScript. Is there anything there? Here is the code.

items = init['items'] itemsKeyedById = {i["id"]: i for i in items} # hard to convert. for item in items: if item["parents"][0]['isRoot'] == False: parent = itemsKeyedById[item["parents"][0]['id']] if "children" not in parent: parent["children"] = [] parent["children"].append(item) topLevelItems = [item for item in items if item["parents"][0]['isRoot'] == True] # hard to convert. try: return json.dumps(topLevelItems[0]); except: return '[]' 
+6
source share
3 answers

In fact, you can run the Python interpreter directly in JS thanks to emscripten .

The project is called empythoned :

Empythoned is a build script that uses Emscripten to compile CPython for use in the browser. He tries to compile the main interpreter as one small executable file and the entire standard library of dynamically loaded libraries.

but be careful:

The project is in its infancy. At the moment, the main interpreter works very well, but many of the libraries either do not work at all, or contain various errors.

+2
source

You should try the following:

http://gatc.ca/projects/pyjsdl/

It works great with regular python and even supports pygame.

+2
source

You might want to learn RapydScript . It is actively supported (as of October 2014) and comes with a few nice examples that really work.

+2
source

All Articles