简体   繁体   English

如何从Javascript执行Python脚本?

[英]How can I execute a Python script from Javascript?

I have written a module in python which performs some function. 我在python中编写了一个执行某些功能的模块。

I then created a Google Chrome extension which makes use of JSON and javascript. 然后,我创建了一个使用JSON和javascript的Google Chrome扩展程序。

Now when I click on the extension I want it to execute the python program which is stored on my hard disk and display the output on the browser again. 现在,当我点击扩展名时,我希望它执行存储在我硬盘上的python程序,并再次在浏览器上显示输出。

Is there a way in which I can do this?? 有没有办法可以做到这一点?

Repeated : 重复 :

Calling Python from JavaScript 从JavaScript调用Python

Here you have some answers, Pyjamas is probably the best option in your case 在这里你有一些答案,睡衣可能是你的最佳选择

可能是一个迟到的回复,但可能的解决方案是让你的python脚本充当服务器,让浏览器插件与之交互。

forgive me if i'm incorrect on infinite proportions. 如果我在无限比例上不正确,请原谅我。

I believe that JavaScript is executed in a sandboxed/ isolated environment. 我相信JavaScript是在沙盒/隔离环境中执行的。 Therefore you cannot invoke a python interpreter* or any other executable residing on the system. 因此,您无法调用python解释器*或驻留在系统上的任何其他可执行文件。

*unless the interpreter itself were written in javascript. *除非解释器本身是用javascript编写的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM