Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何自定义lxml objectify以将INF解析为字符串而不是浮点?_Python_Xml_Lxml - Fatal编程技术网

Python 如何自定义lxml objectify以将INF解析为字符串而不是浮点?

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

使用pythonlxml和objectify,它将
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'>