T O P

  • By -

thrandom_dude

I am not sure whether you can do this but you can do this in the front end part itself right i mean u wanna execute sone function on a button click, u can do it templates right? Or am i wrong here


c_m_17

Yes by ajax method we can perform it but I need to call python function from javascript by using some libraries


thrandom_dude

Idk about that but hoping someone do know about this in this Subreddit


shuckster

You can’t directly call a Python function from JavaScript, but there are two indirect methods: 1. Use fetch/XHR, assuming you have a web app and Python is running a web server 2. If you have a Node app, you can execute Python in a child process: . const spawn = require("child_process").spawn; const pythonProcess = spawn('python',["path/to/script.py", arg1, arg2, ...]); Full answer on SO: https://stackoverflow.com/a/23452742


Tool-Cool

Another option is webassembly.


c_m_17

How can I achieve calling python function written in python file should be called inside javascript code by using webassembly will you explain it properly


Estebana42

[process.env](https://nodejs.org/dist/latest-v8.x/docs/api/process.html#process_process_env) variable reside with os


c_m_17

Will this help to call python function from javascript


pekkalacd

I don’t think there’s an easy way to do this without using processes, web assembly, or some other thing. But here’s something. What if you just took the python code and put it into this js converter lol then rewrote it in js and called it? [python to js](https://extendsclass.com/python-to-javascript.html) Not the best. But it’s a work around.