javascript - Python 到 JavaScript 转换器

标签 javascript python

<分区>

我想将一些基本片段转换为 JavaScript,只是我自己编写的纯 Python 为纯 JavaScript。外面有什么东西吗?这是代码。

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 '[]'

@Davide: Sadly this question has been closed, otherwise I'd write an answer instead of a comment. The best way to do have python as client side these days is with https://github.com/qquick/Transcrypt

最佳答案

感谢 emscripten,您实际上可以直接在 JS 中运行 Python 解释器.

项目名为empythoned :

Empythoned is a build script that uses Emscripten to compile CPython for use in a browser. It attempts to compile the main interpreter as a single small executable and the whole standard library as dynamically loaded libraries.

但要注意:

The project is in its infancy. Right now the core interpreter works very well, but many of the libraries either don't work at all or contain various bugs.

关于javascript - Python 到 JavaScript 转换器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22595989/

相关文章:

python - pandas DataFrame 单列中的多个值

python - 使用 Django REST Framework 更新 USERNAME_FIELD 时如何处理 token

python - 如何从 python 中的字符串中删除 ANSI 转义序列

javascript - 数据表columndef渲染没有被命中并且没有错误

javascript - HTML5 音频有时无法加载

javascript - 提交按钮中的多次 onClick

python - 错误消息 "Linter pylint is not installed"

python - 如何在 Django 中用户未输入数据的情况下在 POST 请求中发送数据

javascript - 这个 RxJS 史诗流有更好的解决方案吗?

javascript - history.go(-1) 返回在 Chrome 中不起作用