如何导入XML数据 (python3.6.6区别于python2 环境)

1.在python2中

代码如下图:

放在python3 环境下执行,将出现如下错误:

原因:

python2中形如myTree.keys()[0]这样的写法是没有问题的,因为myTree.keys()返回的是一个list;

而在python3中myTree.key()返回的则是dick_keys类型,故而出错

解决方法:

将myTree.keys()[0]改为list(myTree.keys())[0]

 注:参考链接

https://blog.csdn.net/qq_33363973/article/details/77877485

原文地址:https://www.cnblogs.com/developmental-t-xxg/p/9209026.html