Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.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
Xml 额外价值';无';被打印出来,我不知道';我不知道为什么_Xml_Python 3.x_Elementtree - Fatal编程技术网

Xml 额外价值';无';被打印出来,我不知道';我不知道为什么

Xml 额外价值';无';被打印出来,我不知道';我不知道为什么,xml,python-3.x,elementtree,Xml,Python 3.x,Elementtree,我尝试使用两个函数解析XML文档,一个用于解析标题,另一个用于解析数据。在每个函数打印输出的末尾,我都会得到一个“None”值。我不知道为什么会这样 任何帮助或建议都将不胜感激。多谢各位 XML文件: <datafile> <header> <name>header_name</name> </header> <game name="game_name"> </game&

我尝试使用两个函数解析XML文档,一个用于解析标题,另一个用于解析数据。在每个函数打印输出的末尾,我都会得到一个“None”值。我不知道为什么会这样

任何帮助或建议都将不胜感激。多谢各位

XML文件:

<datafile>
    <header>
        <name>header_name</name>
    </header>
    <game name="game_name">
    </game>
</datafile>
输出:

header_name
None
game_name
None

在Python中,没有显式返回值的函数返回
None
,因此主程序中的两个
print
调用最终都会打印
None
s,因为它们打印的函数隐式返回
None
s

更改:

print(parse_header('test.dat'))
print(parse_games('test.dat'))
致:


在Python中,没有显式返回值的函数返回
None
,因此主程序中的两个
print
调用最终都会打印
None
s,因为它们打印的函数隐式返回
None
s

更改:

print(parse_header('test.dat'))
print(parse_games('test.dat'))
致:

parse_header('test.dat')
parse_games('test.dat')