我下载了一个看起来像 PHP 数组文件的文件,想知道是否有 python 模块或其他将数组转换/导入到 python 字典的方法。 这是 PHP 数组文件开头的示例。
<?php
$legendre_roots = array();
$legendre_roots[2] = array(
-0.5773502691896257645091487805019574556476017512701268760186023264839776723029333456937153955857495252252087138051355676766566483649996508262705518373647912161760310773007685273559916067003615583077550051041144223011076288835574182229739459904090157105534559538626730166621791266197964892168,
0.5773502691896257645091487805019574556476017512701268760186023264839776723029333456937153955857495252252087138051355676766566483649996508262705518373647912161760310773007685273559916067003615583077550051041144223011076288835574182229739459904090157105534559538626730166621791266197964892168);
理想情况下,我想要一本字典,例如:
legendre_roots = { 2: [-0.57735,0.57735], 3: [.......]......}
感谢任何帮助。
最佳答案
一个例子
<?php
$arr = array('test' => 1, 'ing' => 2, 'curveball' => array(1, 2, 3=>4) );
echo json_encode($arr);
?>
# elsewhere, in Python...
import simplejson
print simplejson.loads('{"test":1,"ing":2,"curveball":{"0":1,"1":2,"3":4}}')
关于php - 将 php 数组转换为 python 字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21403088/