本文整理汇总了Python中pymei.MeiElement.removeChildrenWithName方法的典型用法代码示例。如果您正苦于以下问题:Python MeiElement.removeChildrenWithName方法的具体用法?Python MeiElement.removeChildrenWithName怎么用?Python MeiElement.removeChildrenWithName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymei.MeiElement
的用法示例。
在下文中一共展示了MeiElement.removeChildrenWithName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_flattenedtree
# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import removeChildrenWithName [as 别名]
def test_flattenedtree(self):
mei = MeiElement("mei")
mus = MeiElement("music")
body = MeiElement("body")
staff = MeiElement("staff")
staff2 = MeiElement("staff")
n1 = MeiElement("note")
n2 = MeiElement("note")
n3 = MeiElement("note")
doc = MeiDocument()
mei.addChild(mus)
doc.root = mei
mus.addChild(body)
body.addChild(staff)
body.addChild(staff2)
staff.addChild(n1)
staff.addChild(n2)
staff2.addChild(n3)
doc.lookBack(n2, "mei")
self.assertEqual(8, len(doc.getFlattenedTree()))
staff.removeChild(n2)
self.assertEqual(7, len(doc.getFlattenedTree()))
self.assertEqual(staff2, doc.getFlattenedTree()[5])
staff.removeChildrenWithName("note")
self.assertEqual(6, len(doc.getFlattenedTree()))
body.deleteAllChildren()
self.assertEqual(3, len(doc.getFlattenedTree()))
children = MeiElementList()
staff3 = MeiElement("staff")
staff4 = MeiElement("staff")
children.append(staff3)
children.append(staff4)
body.children = children
self.assertEqual(5, len(doc.getFlattenedTree()))
elements = [mei, mus, body, staff3, staff4]
for i,el in enumerate(doc.getFlattenedTree()):
self.assertEqual(elements[i], doc.getFlattenedTree()[i])
示例2: test_removechildrenbyname
# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import removeChildrenWithName [as 别名]
def test_removechildrenbyname(self):
p = MeiElement("layer")
el1 = MeiElement("note")
el2 = MeiElement("note")
el3 = MeiElement("chord")
p.addChild(el1)
p.addChild(el2)
p.addChild(el3)
self.assertEqual(3, len(p.children))
p.removeChildrenWithName("note")
self.assertEqual(1, len(p.children))
# check that el1 was not actually deleted
self.assertTrue(el1)