Python 如何自定义lxml objectify以将INF解析为字符串而不是浮点?
使用pythonlxml和objectify,它将Python 如何自定义lxml objectify以将INF解析为字符串而不是浮点?,python,xml,lxml,Python,Xml,Lxml,使用pythonlxml和objectify,它将INF转换为浮点。有没有办法将INF作为字符串而不是浮点数输出 from lxml import objectify value=''' <outside> <inside>INF</inside> </outside> ''' root = objectify.fromstring(value) inside = root.inside print insid
INF
转换为浮点。有没有办法将INF作为字符串而不是浮点数输出
from lxml import objectify
value='''
<outside>
<inside>INF</inside>
</outside>
'''
root = objectify.fromstring(value)
inside = root.inside
print inside, inside.__class__
从lxml导入objectify
值=“”
INF
'''
root=objectify.fromstring(值)
inside=root.inside
内部打印,内部打印__
输出:
inf <type 'lxml.objectify.FloatElement'>
inf
在内的标签上设置:
<outside xmlns:py="http://codespeak.net/lxml/objectify/pytype">
<inside py:pytype='str'>INF</inside>
</outside>
INF
演示:
来自lxml导入objectify的>
>>>值=“”
...
... INF
...
... '''
>>>root=objectify.fromstring(值)
>>>inside=root.inside
>>>内部打印,内部打印__
INF
您可以添加或使用。
>>> from lxml import objectify
>>> value = '''
... <outside xmlns:py="http://codespeak.net/lxml/objectify/pytype">
... <inside py:pytype='str'>INF</inside>
... </outside>
... '''
>>> root = objectify.fromstring(value)
>>> inside = root.inside
>>> print inside, inside.__class__
INF <type 'lxml.objectify.StringElement'>