相关疑难解决方法(0)

Python相当于PHP的compact()和extract()

compact()和extract()是PHP中的函数我发现非常方便.compact()获取符号表中的名称列表,并仅使用其值创建哈希表.提取物恰恰相反.例如,

$foo = 'what';
$bar = 'ever';
$a = compact('foo', 'bar');
$a['foo']
# what
$a['baz'] = 'another'
extract(a)
$baz
# another
Run Code Online (Sandbox Code Playgroud)

有没有办法在Python中做同样的事情?我环顾四周,最接近我的是这个线程,它似乎皱着眉头.

我知道locals(),globals()和vars(),但我怎样才能轻松选择其值的一个子集?

Python有没有更好的东西可以避免这种需要?

php python dictionary

9
推荐指数
3
解决办法
6331
查看次数

标签 统计

dictionary ×1

php ×1

python ×1