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

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -