Python 如何将DOM元素对象列表附加到另一个DOM元素对象列表
我从一个XML文件中列出了一些DOM元素,并保存在列表1中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
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))