当前位置: 首页>>代码示例>>Python>>正文


Python SimpleXMLElement.a方法代码示例

本文整理汇总了Python中pysimplesoap.simplexml.SimpleXMLElement.a方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleXMLElement.a方法的具体用法?Python SimpleXMLElement.a怎么用?Python SimpleXMLElement.a使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pysimplesoap.simplexml.SimpleXMLElement的用法示例。


在下文中一共展示了SimpleXMLElement.a方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_attributes_access

# 需要导入模块: from pysimplesoap.simplexml import SimpleXMLElement [as 别名]
# 或者: from pysimplesoap.simplexml.SimpleXMLElement import a [as 别名]
 def test_attributes_access(self):
     span = SimpleXMLElement('<span><a href="python.org.ar">pyar</a><prueba><i>1</i><float>1.5</float></prueba></span>')
     text = "pyar"
     self.eq(str(span.a), text, 'Access by __getattr__:')
     self.eq(str(span.a), text, 'Access by __getattr__:')
     self.eq(str(span('a')), text, 'Access by __call__:')
     self.eq(str(span.a(0)), text, 'Access by __call__ on attribute:')
     self.eq(span.a['href'], "python.org.ar", 'Access by __getitem__:')
     self.eq(int(span.prueba.i), 1, 'Casting to int:')
     self.eq(float(span.prueba.float), 1.5, 'Casting to float:')
开发者ID:anzenehansen,项目名称:pysimplesoap,代码行数:12,代码来源:simplexmlelement_test.py

示例2: test_basic

# 需要导入模块: from pysimplesoap.simplexml import SimpleXMLElement [as 别名]
# 或者: from pysimplesoap.simplexml.SimpleXMLElement import a [as 别名]
    def test_basic(self):
        span = SimpleXMLElement('<span><a href="python.org.ar">pyar</a><prueba><i>1</i><float>1.5</float></prueba></span>')
        span1 = SimpleXMLElement('<span><a href="google.com">google</a><a>yahoo</a><a>hotmail</a></span>')
        self.eq([str(a) for a in span1.a()], ['google', 'yahoo', 'hotmail'])

        span1.add_child('a', 'altavista')
        span1.b = "ex msn"
        d = {'href': 'http://www.bing.com/', 'alt': 'Bing'}
        span1.b[:] = d
        self.eq(sorted([(k, v) for k, v in span1.b[:]]), sorted(d.items()))

        xml = '<?xml version="1.0" encoding="UTF-8"?><span><a href="google.com">google</a><a>yahoo</a><a>hotmail</a><a>altavista</a><b alt="Bing" href="http://www.bing.com/">ex msn</b></span>'
        self.eq(span1.as_xml(), xml)
        self.assertTrue('b' in span1)

        span.import_node(span1)
        xml = '<?xml version="1.0" encoding="UTF-8"?><span><a href="python.org.ar">pyar</a><prueba><i>1</i><float>1.5</float></prueba><span><a href="google.com">google</a><a>yahoo</a><a>hotmail</a><a>altavista</a><b alt="Bing" href="http://www.bing.com/">ex msn</b></span></span>'
        self.eq(span.as_xml(), xml)

        types = {'when': datetime.datetime}
        when = datetime.datetime.now()
        dt = SimpleXMLElement('<when>%s</when>' % when.isoformat())
        self.eq(dt.unmarshall(types)['when'], when)
开发者ID:anzenehansen,项目名称:pysimplesoap,代码行数:25,代码来源:simplexmlelement_test.py


注:本文中的pysimplesoap.simplexml.SimpleXMLElement.a方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。