0

I'm running a python script with subprocess, which will in turn run another test.py script and get some output.

test.py , does some parsing and outputs the list of dictionaries.

  data = [{'a': 12, 'name':'abc'}, {'a': 16, 'name':xyz}, {'a': 17, 'name': lmn}]

  def func1:
  cmd = 'python {}{}{} {} {}'.format(settings.BASE_DIR,'test.py',arg1,arg2)
  p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
  out, err = p.communicate()
  return(p.returncode,err, out)

  def funct2(request):
    if request.GET:
        statuscode,err,resp = func1(arg1,arg2)       
        if not err and statuscode == 0:
             return HttpResponse(json.dumps({'resp':resp,'status_code':statuscode,'err':err}),content_type="application/json")

So that i can handle this data in my javascript to get json object. As of now in my .js file its coming has string even after JSON.parse(resp)

My question is how do i send output of test.py as a list only and handle it further to get a JSON object in my javascript as shown below.

Rachel
  • 247
  • 6
  • 19

0 Answers0