• xml模块和shelve模块


    一、xml模块

    xml是实现不同语言或程序之间进行数据交换的协议,跟json差不多,但json使用起来更简单,不过,古时候,在json还没诞生的黑暗年代,大家只能选择用xml呀,至今很多传统公司如金融行业的很多系统的接口还主要是xml。

    <?xml version="1.0"?>
    <data>
        <country name="Liechtenstein">
            <rank updated="yes">2</rank>
            <year>2008</year>
            <gdppc>141100</gdppc>
            <neighbor name="Austria" direction="E"/>
            <neighbor name="Switzerland" direction="W"/>
        </country>
        <country name="Singapore">
            <rank updated="yes">5</rank>
            <year>2011</year>
            <gdppc>59900</gdppc>
            <neighbor name="Malaysia" direction="N"/>
        </country>
        <country name="Panama">
            <rank updated="yes">69</rank>
            <year>2011</year>
            <gdppc>13600</gdppc>
            <neighbor name="Costa Rica" direction="W"/>
            <neighbor name="Colombia" direction="E"/>
        </country>
    </data>

    xml协议在各个语言里的都 是支持的,在python中可以用以下模块操作xml:

    print(root.iter('year')) #全文搜索
    print(root.find('country')) #在root的子节点找,只找一个
    print(root.findall('country')) #在root的子节点找,找所有

    二、shelve模块

    shelve模块比pickle模块简单,只有一个open函数,返回类似字典的对象,可读可写;key必须为字符串,而值可以是python所支持的数据类型

    import shelve

    f=shelve.open(r'sheve.txt')
    # f['stu1_info']={'name':'egon','age':18,'hobby':['piao','smoking','drinking']}
    # f['stu2_info']={'name':'gangdan','age':53}
    # f['school_info']={'website':'http://www.pypy.org','city':'beijing'}

    print(f['stu1_info']['hobby'])
    f.close()

  • 相关阅读:
    .NETCore_初探
    .NETCore_生成实体
    架构碎屑
    Helper
    26.【转载】挖洞技巧:绕过短信&邮箱轰炸限制以及后续
    25.【转载】挖洞技巧:支付漏洞之总结
    24.【转载】挖洞技巧:信息泄露之总结
    5.Windows应急响应:挖矿病毒
    4.Windows应急响应:勒索病毒
    3.Windows应急响应:蠕虫病毒
  • 原文地址:https://www.cnblogs.com/bailongcaptain/p/12608726.html
Copyright © 2020-2023  润新知