0

I have a python script which outputs a JSON when called with different arguments. I am looking for a way to call that script from within Processing and load the output using something like loadJSONObject()

The problem is that I don't know how to call the python script with arguments from within Processing.

Any tip will be appreciated, thanks!

6
  • stackoverflow.com/help/mcve Commented Apr 29, 2015 at 19:04
  • @felipsmartins I'm sorry I don't have an example because I don't know if there is a way it can be done. That is the purpose of my question. Do you know how to call python with arguments from within Processing? Thanks. Commented Apr 29, 2015 at 19:07
  • 2
    Are you looking for the open function? processing.org/reference/open_.html Commented Apr 29, 2015 at 19:07
  • @JasonSperske Thanks, not sure if that will do it but I will definitely try if I can pass the output of the python to a String using Open() Thanks a lot. I let you know if it works so you can make it an answer. Commented Apr 29, 2015 at 19:09
  • Add a link to the processing library you are using. Is it this one? pypi.python.org/pypi/processing Commented Apr 29, 2015 at 19:12

1 Answer 1

1

One option, as pointed out in the comments, is to use open, and then load the file that generates the normal way.

Another -arguably much better- way is to not do this and to run your python script as services with a web interface instead, so that your python scripts sits listening on http://localhost:1234, for instance, and your Processing sketch can simply load a file "http://localhost:1234/somefile?input=whatever" and not even care what is actually generating the content.

The upside there is also that you can run your script anywhere that can be reached via URLs, and those things don't need to rely on python being available as an executable.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot Mike. Your option is the best, actually I thought to myself something similar but I know how to do that with PHP I did not know I was able to do the same with python and send the parameters in the URL and make python read them. I will learn more about python as a web service.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.