使用JavaScript触发Python脚本
我正在进行一个小项目,在Python和图形用户界面Woth HTML,CSS& JS。
Python脚本不需要任何外部库,并且它唯一要做的就是用处理数据打开JSON文件,因为它是游戏,因此结果是随意生成的,因此我不必将任何参数传递给脚本。 问题是我不知道如何触发脚本,因此它可以生成可以访问jabascript的JSON。
该项目的计划是: index.html
页面(文件夹)
- newgame.html
- loadgame.html
- prule.html
python(folder)
- python_script1.py
- python_script2.py python_script2.py
- python_script3.py
- main.py main.py,
我必须具体触发脚本或poad load load load load load loadgame page newgame页面一。
(obiuvsly js不是node.js是实际的客户端JavaScript)
我obiuvsly进行了一些研究,我发现pyodyde开源项目可以做我想要的,事实是我无法找到如何连接界面用此资源与后端一起文件。
I am doing a little project where i have prepared the back end in python and the graphic user interface woth HTML, CSS & JS.
The python script doesn't require any external librariesand the only thing that it does is opening a JSON file with the data processed, since it's a game the results are casually generated, and because of this I don't have to pass any parameters to the script.
The problem is that I don't know how to trigger the script so it generates the json that i can access trough JabaScript.
the scheme of the project is this:
index.html
pages (folder)
- newGame.html
- loadGame.html
- rules.html
python (folder)
- python_script1.py
- python_script2.py
- python_script3.py
- main.py
specifically i have to trigger the script once the user has loaded the newGame page or the loadGame one.
(obiuvsly the js isn't node.js is actual client-side JavaScript)
I obiuvsly did some research and i found the pyodyde open source project does what i want, the fact is that i can't figure out how to connect the interface file with the back-end one with this resource.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
解决方案
好,在其他一些研究中,我发现了如何解决问题。
但首先,我要感谢你们向我推荐了Pyscript库。
我遇到的问题是我需要在Pyscript标签中连接Python文件。
首先,我必须用
import
关键字导入它,而不是执行文件。但是我发现PY-Script标签具有
src
属性,您可以链接所有想要的外部文件。因此,最后,我要做的就是连接我的文件是:
solution
Ok, with some other research i found out how to solve my problem.
But firstable I want to thank you guys for recommending me the PyScript library.
The problem I was having is that i needed to connect a python file within the pyscript tag.
At first i tought that I had to import it with the
import
keyword and than executing the file.But than I discovered that the py-script tag has an
src
attribute and you can link all the external files that you want.So, in the end, iall i had to do was to connect my file is this:
有一个名为Pyscript的新库(它可以帮助您在HTML中运行Python),安装CLI所需要做的就是执行此命令:
pip install pyscript-cli
(此命令将安装CLI而不是库)。然后,您应该执行此命令:
Pyscript Wrap Python_file.py
(注意:这将将Python文件转换为HTML文件,因此Python文件名是HTML文件的名称)而且应该做。
HTML代码将是:
There is a new library called PyScript (it can help you run python in your HTML), all you need to do to install the cli is doing this command:
pip install pyscript-cli
(This command will install the cli not the library).then you should do this command:
pyscript wrap python_file.py
(NOTE: this will convert the python file to an html file so the python file name would be the name of the html file)And it should be done.
The HTML code would be this:
但是,一旦我输入命令并从Python脚本创建了HTML文件,我该如何将其连接到“ Newlevel”页面?
But than, once i typed in the command and created the html file from the python script, how do I connect it to the "newLevel" page?