本文整理汇总了Python中elementtree.ElementTree.Element.attrib['im']方法的典型用法代码示例。如果您正苦于以下问题:Python Element.attrib['im']方法的具体用法?Python Element.attrib['im']怎么用?Python Element.attrib['im']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类elementtree.ElementTree.Element
的用法示例。
在下文中一共展示了Element.attrib['im']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: encode
# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import attrib['im'] [as 别名]
def encode(key, value):
element = Element(key)
if isinstance(value, NoneType):
element.attrib['type'] = 'none'
elif isinstance(value, BooleanType):
element.attrib['type'] = 'bool'
element.attrib['value'] = value and 'true' or 'false'
elif isinstance(value, ComplexType):
element.attrib['type'] = 'complex'
element.attrib['re'] = repr(value.real)
element.attrib['im'] = repr(value.imag)
elif isinstance(value, FloatType):
element.attrib['type'] = 'float'
element.attrib['value'] = repr(value)
elif isinstance(value, IntType):
element.attrib['type'] = 'int'
element.attrib['value'] = repr(value)
elif isinstance(value, LongType):
element.attrib['type'] = 'long'
element.attrib['value'] = repr(value)
elif isinstance(value, StringType) or isinstance(value, UnicodeType):
element.attrib['type'] = 'cdata'
element.text = u"<![CDATA[%s]]>" % value
elif isinstance(value, DictType):
element.attrib['type'] = 'dict'
for key in value.keys():
element.append(encode(key, value[key]))
elif isinstance(value, ListType):
element.attrib['type'] = 'list'
for subvalue in value:
element.append(encode('value', subvalue))
elif isinstance(value, TupleType):
element.attrib['type'] = 'tuple'
for subvalue in value:
element.append(encode('value', subvalue))
else:
raise TypeError("Encoding of %s not supported (Key: %s)" % (repr(value), key))
return element