本文整理汇总了Python中pymei.MeiElement.attributes方法的典型用法代码示例。如果您正苦于以下问题:Python MeiElement.attributes方法的具体用法?Python MeiElement.attributes怎么用?Python MeiElement.attributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymei.MeiElement
的用法示例。
在下文中一共展示了MeiElement.attributes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: switch_tie
# 需要导入模块: from pymei import MeiElement [as 别名]
# 或者: from pymei.MeiElement import attributes [as 别名]
def switch_tie(meifile, tstamp = False, keep_id = False):
''' Changes all ties expressed with attributes into elements.
If tstamp is set, it will attempt to generate tstamps instead of startid/endid pairs.
@TODO
At some point search() will support
passing in args will narrow down the search by only retrieving objects with that attribute.
Make sure to update this function when that happens
'''
meifile_flat = meifile.getFlattenedTree()
for n in meifile_flat:
if n.hasAttribute('tie'):
if n.getAttribute("tie").value =='i' or n.getAttribute("tie").value == 'm': #one tie element for each tie!
#get ancestor measure
measure = n.getAncestor('measure')
#create a tie element
tie = MeiElement("tie")
#determine attributes according to args
# atts = {'xml:id': generate_mei_id()}
atts = MeiAttributeList()
if tstamp:
atts.append(MeiAttribute("tstamp", str(time.id_to_tstamp(n))))
# atts['tstamp'] = time.id_to_tstamp(n)
if keep_id or (not keep_id and not tstamp):
atts.append(MeiAttribute("startid", n.id))
# atts['startid'] = n.id
#add attributes to tie
tie.attributes = atts
#add tie to measure
measure.addChild(tie)
#remove tie attribute
n.removeAttribute('tie')