当前位置: 首页>>代码示例>>Python>>正文


Python MeiElement.attributes方法代码示例

本文整理汇总了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')
开发者ID:AFFogarty,项目名称:libmei,代码行数:39,代码来源:attribute_to_element.py


注:本文中的pymei.MeiElement.attributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。