</div>
</div>
<div class="grid--cell mb0 mt8">Closed <span title="2012-10-03 14:39:28Z" class="relativetime">7 years ago</span>.</div>
</div>
</aside>
Possible Duplicate:
Calling Python from JavaScript
I have a test.py
and test.js
.
I want to be able to run my test.py
by opening test.js
. I don't know how to create an api because it's not a web app, it's just 2 files sitting on my linux mint desktop.
I don't want to use npapi, because it's just a simple task, i don't want to use pyjamas because it's too hard to install the pyjamas desktop, so how to do it?
please note that i can use php, ajax, jquery instead of javascript, if it could be done with these languages. I am also able to use C++ or C instead of python. I just want to know a simple way to do it.
I know this can be done if i use java instead of python, but i want to know if i can do it with python, C or C++.
</div>
If you put your test.py file where ever you put your cgi files, (I think it's /usr/lib/cgi-bin by default for apache on ubuntu linux), you should be able to run the python file just by making a request to it's address.
If you just want to run the python file, and not use its output in the browser afterward, you could probably get away with something like:
document.write('<img src="http://localhost/cgi-bin/test.py" />');
if you want to use the output in the browser, you will probably be best served by using jQuery or some other library to do an easy ajax call.
something like:
jQuery.get('/cgi-bin/test.py', function(data) {
//do stuff with the data
})
would probably do you just fine.
the second method would require that you also use apache, or equivalent, to serve the test.js file from localhost because jQuery ajax generally requires requests to go to the same domain that the script is running on.