本文整理汇总了Python中pymei.MeiElement.getDescendantsByName方法的典型用法代码示例。如果您正苦于以下问题:Python MeiElement.getDescendantsByName方法的具体用法?Python MeiElement.getDescendantsByName怎么用?Python MeiElement.getDescendantsByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymei.MeiElement
的用法示例。
在下文中一共展示了MeiElement.getDescendantsByName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_segfaultdebug
# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import getDescendantsByName [as 别名]
def test_segfaultdebug(self):
variants_list = [
('3', 'VARIANT', '2', 'RISM1560-06'),
('6', 'VARIANT', '5', 'RISM1560-06')
]
res = documentFromFile(os.path.join("test", "testdocs", "DC1317E.mei"))
MEI_doc = res.getMeiDocument()
mei = MeiElement('mei')
# print(mei)
head_score = chain_elems(mei, ['meiHead', 'workDesc', 'work', 'incip', 'score'])
stg = chain_elems(mei, ['music', 'body', 'mdiv', 'score', 'scoreDef', 'staffGrp'])
sd1 = MeiElement('staffDef')
sd2 = MeiElement('staffDef')
sd3 = MeiElement('staffDef')
sd4 = MeiElement('staffDef')
sd5 = MeiElement('staffDef')
sd6 = MeiElement('staffDef')
sd1.addAttribute('n', '1')
sd2.addAttribute('n', '2')
sd3.addAttribute('n', '3')
sd4.addAttribute('n', '4')
sd5.addAttribute('n', '5')
sd6.addAttribute('n', '6')
stg.addChild(sd1)
stg.addChild(sd2)
stg.addChild(sd3)
stg.addChild(sd4)
stg.addChild(sd5)
stg.addChild(sd6)
MEI_tree = MEI_doc.getRootElement()
# MEI_tree2 = mei
# print(MEI_tree)
# print MEI_tree2
scoreDefs = MEI_tree.getDescendantsByName('scoreDef')
# print(scoreDefs)
mainScoreDef = MeiElement(scoreDefs[0])
mainScoreDef.id = "blahblahblah"
meiHead = MEI_tree.getDescendantsByName('meiHead')[0]
head_score = chain_elems(meiHead, ['workDesc', 'work', 'incip', 'score'])
head_score.addChild(mainScoreDef)
for variants_list_item in variants_list:
stDefs = mainScoreDef.getDescendantsByName('staffDef')
for staffDef in stDefs:
if staffDef.hasAttribute('n') and staffDef.getAttribute('n').value == variants_list_item[0]:
print("Removing staffDef n=" + staffDef.getAttribute('n').getValue())
staffDef.parent.removeChild(staffDef)
# head_score.addChild(mainScoreDef)
self.assertEqual(8, len(head_score.getDescendantsByName('staffDef')))