Return json from python -


i have simple module in drupal expecting 4 values in json python script. believe python script collecting data need fine:

 # information easy via xpath html ids tree = etree.html(tree) make = tree.xpath('//div[@id="makedata"]')[0] model = tree.xpath('//div[@id="modeldata"]')[0] manufacture_year = tree.xpath('//div[@id="manufactureyeardata"]')[0] engine_size = tree.xpath('//div[@id="enginesizedata"]')[0] 

now need return data drupal module can catch this:

  // execute script , store output in variable $py_output = shell_exec($cmd);  // assuming output json string. $data = drupal_json_decode($py_output); 

i don't know python, searching around lead me try this:

return json.dumps({'make': make,                    'model': model,                    'year': year,                    'engine': engine}) 

that doesn't seem work. appreciated!


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -