I have a Python script and a JS on my server. In the python script, I want to set the value of a variable to be the output of one of the functions in my .js file.
Is this possible, and if so how wold one go about doing this?
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As an alternative to what Macha proposes (an Ajax query) you could also create the Javascript file dynamically.
When the page is loaded, the javascript is loaded. In your page is the URL to the javascript in the form of
The trick is now to let the server not serve a static file “mycode.js” but the output of e.g. mycode.py. Your tag would thus look like
and the python script would look possibly like (simplified):
In short, you have your current js file, but you’d use it as a template for the python script. You substitute your variable with its value using replace.
It may not be the most elegant solution but it should work, and isn’t all that difficult to understand.
Don’t forget that your server should know how to handle python scripts 🙂