Reputation: 55
Due to some restrictions on what I'm allowed to use, I had to create a dictionary with arrays as values in PHP. At the end of my script, I put a return statement to return the dictionary. I now have to run a clustering algo in Python with this map. I tried to run
proc = subprocess.call(["php", "/path/to/file/file.php"])
To store the dictionary as proc. I then printed the type of proc and then the value just to have an idea if it stored the data correctly, however, the type was int, and the value was 0. (The keys in this dictionary are all strings, with arrays of integers as the values). Any idea on why I'm getting these return values? Or a better way to import my dictionary to Python 2.7?
Thanks!
Upvotes: 0
Views: 275
Reputation: 113988
I struggle to comprehend a senario where this is a good idea...but regardless
<?php
$data = array("1"=>2,"3"=>5,"asd"=>22,"bob"=>"susan");
echo json_encode($data);
?>
>>> import subprocess,json
>>> json.loads(subprocess.check_output("php test.php",shell=True))
{u'1': 2, u'3': 5, u'bob': u'susan', u'asd': 22}
Upvotes: 2