使用类似json的路径表示法访问嵌套的dict和list。

jpath的Python项目详细描述


使用类似json的路径表示法访问嵌套的dict和list。

注意,这段代码是为python 3编写的。

符号如下:

You can just write the names of components in your path like you would in javascript:

foo.bar.baz

To access arrays or names with spaces in them, use the ‘[]’ notation. You can use negative indices with arrays to count from the end.

[“foo”][“bar”][“baz”] array[-1].attr [3]

You can use the wildcard character ‘*’ to iterate over all elements:

foo.*.baz [“foo”][*][“baz”]

This may return more or less than a single element. Use get to get the first one, and get_all to get a list of all possibilities. If you want to skip any number of elements in path, use two dots ‘..’:

foo..baz

You can slice the arrays just like in python:

array[1:-1:2]

Finally, you can filter the elements:

foo(bar.baz=true) foo.bar(baz>0).baz foo(bar=”yawn”).bar

At the moment only =, >, <, >=, <= and != operators are available, and you can only use them with strings, integers and boolean values.

下面这段代码是用stx写的。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
swing Java JScrollBar设计   java如何按名称显示输出   java如何将多个ArrayList连接成一个?   java存储SSLSocketFactory为静态字段   java获得了奇怪的csv文件时间输出   java类在JSP中没有该属性   java ehcache程序未运行   java如何对数组的所有元素应用或操作?   sqlite如何用Java编写adb shell命令   java泛型中的动态数据类型   javajaxrs@Path阻止加载静态资源   java如何在安卓中从主字符串中获取特定字符串?   java与FLAG_LAYOUT_NO_LIMITS相反   关于OpenJDK 11和OpenJFX 11(&Proguard)的java迁移问题   eclipse设置Selenium for Java(创建Firefox驱动程序所需的JAR和导入)   java如何将空字符串更新为oracle Clob   对象为什么在Java中同时重写equals()和hashCode()?   java从另一个类获取变量的正确方法