listmodel是一个python库,用于以统一方式为各种列表源(xml文档、csv文档、文本文档、json/yaml对象)进行对象映射。

listmodel的Python项目详细描述


listmodel是一个python库,用于以统一方式为各种列表源(xml文档、csv文档、文本文档、json/yaml对象)进行对象映射。灵感来自QMLXmlListModel

基本用法

>>>fromlistmodelimportXMLDoc,QueryAttr,set_name>>>xml=u"""<bookshelf>
...         <name>My Bookshelf</name>
...         <book>
...             <title>1984</title>
...             <author>Orwell, George</author>
...             <isbn>978-0-452-28423-4</isbn>
...             <chapter id="1">...</chapter>
...             <chapter id="2">...</chapter>
...             <chapter id="3">...</chapter>
...         </book>
...         <book>
...             <title>The man in the high castle</title>
...             <author>Dick, Philip K.</author>
...             <isbn>0679740678</isbn>
...             <chapter id="1">...</chapter>
...             <chapter id="2">...</chapter>
...             <chapter id="3">...</chapter>
...         </book>
...     </bookshelf>
... """>>>classBookshelf(XMLDoc):...classIterable(XMLDoc):...__query__="/bookshelf/book"......@set_name("Chapter")...classIterable(XMLDoc):...__query__="chapter"...id=QueryAttr("@id")......isbn=QueryAttr("isbn/text()")...title=QueryAttr("title/text()")...author=QueryAttr("author/text()")......@QueryAttr("author/text()")...defauthor_first_name(self,value):...returnvalue.split(", ")[1]......name=QueryAttr("/bookshelf/name/text()")>>>shelf=Bookshelf.fromstring(xml)>>>shelf<Bookshelf(name='My Bookshelf')>>>>shelf.name'My Bookshelf'>>>books=list(shelf)>>>len(books)2>>>books[1].title'The man in the high castle'>>>books[1].author_first_name'Philip K.'>>>list(books[0])[<Chapter(id='1')>,<Chapter(id='2')>,<Chapter(id='3')>]

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

推荐PyPI第三方库


热门话题
在IE10中重新加载另一个帧时,internet explorer Java小程序失败/消失   ThreadLocal变量的java性能   java系统。出来println不是打印输出   java从JAXB类获取元素属性   java组织。天啊。科尔巴。包裹。InvalidName:IDL:omg。org/CORBA/ORB/InvalidName:1.0   java有没有办法让非事务连接抛出异常?   java是否有任何方法可以使用JdbcTemplate和查询/条件Fluent API   javajpa级联类型。刷新不工作?   未考虑java Maven依赖关系管理   java MySQL MBR包含抛出MySQLExceptionError的语句   java验证整数并将其设为5位数   java发现了循环依赖的问题   java Hibernate left join fetch到使用@ManyToMany关联映射的softdeleted实体生成无效查询?   JavaH:commandButton多个操作:下载文件并呈现ajax表   Google Contacts API在Java、C#、Python或Ruby中是否有一个Hello World示例?