python数据操作让大脑死亡
manipulator的Python项目详细描述
python的数据操作让人头脑发热。
安装
pip install manipulator
用法
manipulator主要公开三个函数,get、update和set。 get检索数据,update根据其形式对其进行转换,以及set 通过简单的重置来转换它。转换可以就地应用或 一份副本。默认设置已就位,因为复制成本很高。如果你想 复制数据,将关键字参数in_place设置为True。
它使用的查询“语言”与css没有什么不同,尽管要简单得多。唯一的 这个“语言”中的两个实体是用#表示的id和用 .。ID是唯一的,而类是所有叶值的集合 顺从。
一些激励性的例子(可以在test目录中找到更详尽的列表):
importmanipulatormanipulator.get({"k":[1,[2],3]},"#k #1 #0")# => 2 (note how list indices are coerced into integers)manipulator.get([{"k":"v"},{"k":"v2","k2":"v3"}],".k")# => ["v", "v2"]manipulator.get([{"k":"v"},{"k":{"a":[{"k":10},{"k":11}]}}],".k #1 #a .k")# => [10, 11]manipulator.set({"k":[1,[2],3]},"#k #1 #0",3)# => {"k": [1, [3], 3]} (in place)manipulator.set({"k":[1,[2],3]},"#k #1 #0",3,in_place=False)# => {"k": [1, [3], 3]} (will create a copy of the data)manipulator.set([{"k":"v"},{"k":{"a":[{"k":10},{"k":11}]}}],".k #1 #a .k",100)# => [{"k": "v"}, {"k": {"a": [{"k": 100}, {"k": 100}]}}]manipulator.update({"k":[1,[2],3]},"#k #1 #0",lambdax:x-1)# => {"k": [1, [1], 3]} (in place, use in_place=False to copy)manipulator.update([{"k":"v"},{"k":{"a":[{"k":10},{"k":11}]}}],".k #1 #a .k",lambdax:x+1)# => [{"k": "v"}, {"k": {"a": [{"k": 11}, {"k": 12}]}}]
仅此而已。
玩得开心!