Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/321.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 如何将DOM元素对象列表附加到另一个DOM元素对象列表_Python_Dom - Fatal编程技术网

Python 如何将DOM元素对象列表附加到另一个DOM元素对象列表

Python 如何将DOM元素对象列表附加到另一个DOM元素对象列表,python,dom,Python,Dom,我从一个XML文件中列出了一些DOM元素,并保存在列表1中 list1 = [<DOM Element: DeviceInfo at 0x1915c88>, <DOM Element: ManagementServer at 0x1961b70>, <DOM Element: GatewayInfo at 0x19cd5d0>] 预期产出: newList = [<DOM Element: DeviceInfo at 0x1915c88>, &l

我从一个XML文件中列出了一些DOM元素,并保存在列表1中

list1 = [<DOM Element: DeviceInfo at 0x1915c88>, <DOM Element: ManagementServer at 0x1961b70>, <DOM Element: GatewayInfo at 0x19cd5d0>]
预期产出:

newList = [<DOM Element: DeviceInfo at 0x1915c88>, <DOM Element: ManagementServer at 0x1961b70>, <DOM Element: GatewayInfo at 0x19cd5d0>,[<DOM Element: VendorConfigFile__INSTANCE__ at 0x1915f08>, <DOM Element: SupportedDataModel__INSTANCE__ at 0x191bda0>]]
newList=[,[,]]
但我在新名单中被列为“无”

到底是什么问题,以及如何做到这一点

多谢各位


在我的列表中,它包含
和许多这样的DOM元素对象,
中的内容不会显示在列表中

已更新

追加的返回类型为
None
。 因此,
list1.append(list2)
给出了
None
,但也改变了
list1
。 所以你应该这样做

newList = list(list1)
newList.append(list(list2))

您好,Dinesh,我希望它与列表列表完全相同:我的新列表应该是这样的,newList=[list1,[list2]]如果您的
list1
list2
中不包含包含列表,您可以使用这个。否则使用
deepcopy()
代替
list()
@SharathK没问题。
newList = [<DOM Element: DeviceInfo at 0x1915c88>, <DOM Element: ManagementServer at 0x1961b70>, <DOM Element: GatewayInfo at 0x19cd5d0>,[<DOM Element: VendorConfigFile__INSTANCE__ at 0x1915f08>, <DOM Element: SupportedDataModel__INSTANCE__ at 0x191bda0>]]
newList = list(list1)
newList.append(list(list2))