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


Python Element.set方法代码示例

本文整理汇总了Python中elementtree.ElementTree.Element.set方法的典型用法代码示例。如果您正苦于以下问题:Python Element.set方法的具体用法?Python Element.set怎么用?Python Element.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在elementtree.ElementTree.Element的用法示例。


在下文中一共展示了Element.set方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUp

# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import set [as 别名]
        def setUp(self):
            
            from_string('<temp/>')
            
            s1 = Element('class')
            s1.set('name','test')
            t.append(s1)

            s2 = Element('handler')
            s2.text = "print 'Hi!'"
            s2.set('on','init')
            s1.append(s2)

            self.node1 = s1
            
            doc2 = Element('class')
            doc2.set('name','test2')
            doc2.set('extends','test')

            s3 = Element('handler')
            s3.text = 'print Hi2!'
            s3.set('on','init')

            doc2.append(s3)
            
            self.node2 = doc2
开发者ID:xkenneth,项目名称:wildfire1,代码行数:28,代码来源:helper.py

示例2: create_slide

# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import set [as 别名]
    def create_slide(self, buf, i,name=''):
        # creating the name of the slide
        # by parsing the title and removing any odd character
        slidename = re.sub('[^a-zA-Z0-9\\s]','',name)
        slidename = re.sub('\\s','_',slidename)      

        # we create a new div that will contain the slide
        cont = Element("div") #etree_loader.importETree().Element('div')
        cont.set('class', 'slide')
        cont.set('id', slidename)

        return cont
开发者ID:tlamadon,项目名称:markdown2deckjs,代码行数:14,代码来源:mdx_slider.py

示例3: addLangs

# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import set [as 别名]
def addLangs(element, msg):
    for lang in all_languages:
        elem = Element(ns + 'langstring')
        elem.set('language', lang)
        elem.text = msg
        element.append(elem) 
开发者ID:EU-OSHA,项目名称:osha.policy,代码行数:8,代码来源:parser.py

示例4: rec2format

# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import set [as 别名]
def rec2format (context, recs, output_format='mods'):
    try:
        config = context.config
        source_catalog = context.get_source_catalog()
        ctm = source_catalog.get_complete_mapping()
        
        root = Element('modsCollection')
        root.set('xmlns', 'http://www.loc.gov/mods/v3')
        root.set('xmlns:xlink', 'http://www.w3.org/1999/xlink')
        root.set('version', '3.0')
        root.set('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance')
        root.set('xsi:schemaLocation',
            'http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-0.xsd')
        
        for rec in recs:
            try:
                mods = SubElement(root, 'mods')
                mm = rec.get_mapped_metadata(ctm)
                if mm.get('title', ''):
                    titleInfo = SubElement(mods, 'titleInfo')
                    title = SubElement(titleInfo, 'title')
                    title.text = mm['title']
                if mm.get('author', []):
                    for au in mm['author']:
                        name = SubElement(mods, 'name')
                        name.set('type', 'personal')
                        # Note: bibutils looks for family/given split
                        if ' ' in au:
                            family, given = au.split(' ')
                            namePart = SubElement(name, 'namePart')
                            namePart.set('type', 'given')
                            namePart.text = given
                            namePart = SubElement(name, 'namePart')
                            namePart.set('type', 'family')
                            namePart.text = family
                        else:
                            namePart = SubElement(name, 'namePart')
                            namePart.set('type', 'family')
                            namePart.text = au
                        role = SubElement(name, 'role')
                        roleTerm = SubElement(role, 'roleTerm')
                        roleTerm.set('type', 'text')
                        roleTerm.text = 'author'
                typeOfResource = SubElement(mods, 'typeOfResource')
                typeOfResource.text = 'text'
                
                # The following block is about the "host" journal in which this
                # article appeared
                relatedItem = SubElement(mods, 'relatedItem')
                relatedItem.set('type', 'host')
                titleInfo = SubElement(relatedItem, 'titleInfo')
                title = SubElement(titleInfo, 'title')
                title.text = mm['journal']
                if mm.get('issn', ''):
                    identifier = SubElement(relatedItem, 'identifier')
                    identifier.set('type', 'issn')
                    identifier.text = mm['issn']
                originInfo = SubElement(relatedItem, 'originInfo')
                issuance = SubElement(originInfo, 'issuance')
                issuance.text = 'continuing'
                part = SubElement(relatedItem, 'part')
                if mm.get('volume', ''):
                    detail = SubElement(part, 'detail')
                    detail.set('type', 'volume')
                    number = SubElement(detail, 'number')
                    number.text = mm['volume']
                if mm.get('issue', ''):
                    detail = SubElement(part, 'detail')
                    detail.set('type', 'issue')
                    number = SubElement(detail, 'number')
                    number.text = mm['issue']
                if mm.get('pages', ''):
                    extent = SubElement(part, 'extent')
                    extent.set('unit', 'page')
                    if '-' in mm['pages']:
                        start, end = mm['pages'].split('-')
                        st = SubElement(extent, 'start')
                        st.text = start
                        en = SubElement(extent, 'end')
                        en.text = end
                    else:
                        st = SubElement(extent, 'start')
                        st.text = mm['pages']
                if mm.get('pubdate', ''):
                    date = SubElement(part, 'date')
                    date.text = mm['pubdate'][:4]
                
                for subtype in ['subject', 'keyword']:
                    for sub in mm.get(subtype, []):
                        subject = SubElement(mods, 'subject')
                        if subtype == 'subject':
                            subject.set('authority', 'mesh')
                        topic = SubElement(subject, 'topic')
                        topic.text = sub
                    
            except:
                print traceback.print_exc()
        
        mods_out = etree.tostring(root)
        if output_format == 'mods': 
#.........这里部分代码省略.........
开发者ID:dchud,项目名称:sentinel,代码行数:103,代码来源:utils.py

示例5: main

# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import set [as 别名]
def main():
    if len(sys.argv) != 2: 
            print 'Usage: ' + sys.argv[0] + ' <CSV file>' 
            sys.exit(1) 
        
    pathToCSV = sys.argv[1]
    
    f = open(pathToCSV)
    dataDict = csv.DictReader(f)
    intensity = "Resting"
    triggerMethod = "Distance"

    tcxTrackpoints = {}
    earliestEpochMS = earliestTimeInDict(dataDict)
    earliestEpoch = math.floor(int(earliestEpochMS) / 1000)

    root = Element("TrainingCenterDatabase")
    root.set("xsi:schemaLocation", "http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2 http://www.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd")
    root.set("xmlns:ns2", "http://www.garmin.com/xmlschemas/UserProfile/v2")
    root.set("xmlns:ns3", "http://www.garmin.com/xmlschemas/ActivityExtension/v2")
    root.set("xmlns:ns4", "http://www.garmin.com/xmlschemas/ProfileExtension/v1")
    root.set("xmlns:ns5", "http://www.garmin.com/xmlschemas/ActivityGoals/v1")
    root.set("xmlns", "http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2")
    root.set("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")

    actsElement = SubElement(root, "Activities")
    actElement = SubElement(actsElement, "Activity", Sport="Running")

    idElement = SubElement(actElement, "Id")
    idElement.text = stringGMTimeFromEpoch(earliestEpoch)

    lastTimeEpoch = 0
    
    lapElement = SubElement(actElement, "Lap", StartTime=stringGMTimeFromEpoch(earliestEpoch))
    
    totalDistanceMeters = 0
    maxSpeed = 0
    calories = 0.0
    maxBPM = 0    
    numRows = 0
    totalBPM = 0
    
    trackpoints = list()
    
    for row in dataDict:
        trackpointElement = Element("Trackpoint")
        trackpoints.append(trackpointElement)
        
        # TIME
        epochMS = row['timestamp_epoch']
        epoch = math.floor(int(epochMS) / 1000)
        timeElement = SubElement(trackpointElement, "Time")
        timeElement.text = stringGMTimeFromEpoch(epoch)

        # POSITION
        latValue = row['LATITUDE']
        longValue = row['LONGITUDE']
        
        if (abs(float(latValue)) <= 180 and abs(float(longValue)) <= 180
            and abs(float(latValue)) > 0.1 and abs(float(longValue)) > 0.1):
            posElement = SubElement(trackpointElement, "Position")
            latElement = SubElement(posElement, "LatitudeDegrees")
            latElement.text = latValue
            longElement = SubElement(posElement, "LongitudeDegrees")
            longElement.text = longValue
        
        # Altitude
        alt = row['ELEVATION']
        altElement = SubElement(trackpointElement, "AltitudeMeters")
        altElement.text = alt

        # DISTANCE
        distanceMeters = row['DISTANCE']
        distElement = SubElement(trackpointElement, "DistanceMeters")
        distElement.text = distanceMeters

        # BPM
        heartRate = math.trunc(float(row['HEARTRATE']))
        # if heartRate > 0:
        bpmElement = SubElement(trackpointElement, 'HeartRateBpm xsi:type=\"HeartRateInBeatsPerMinute_t\"')
        bpmValElement = SubElement(bpmElement, "Value")
        bpmValElement.text = str(heartRate)
                
        extElement = SubElement(trackpointElement, 'Extensions')
        
        # SPEED
        speed = float(row['SPEED'])
        speed *= MPS_TO_MPH
        ns3Element = SubElement(extElement, 'ns3:TPX')
        speedElement = SubElement(ns3Element, 'ns3:Speed')
        speedElement.text = str(speed)
                
        if lastTimeEpoch == 0 or epoch > lastTimeEpoch:
            lastTimeEpoch = epoch

        if totalDistanceMeters == 0 or float(distanceMeters) > float(totalDistanceMeters):
            totalDistanceMeters = distanceMeters

        rowCalories = row['CALORIEBURN']        
        calories = rowCalories
#.........这里部分代码省略.........
开发者ID:chazmatazz,项目名称:MotoACTV-tcx,代码行数:103,代码来源:motoactv_tcx.py

示例6: len

# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import set [as 别名]
#  MA 02110-1301 USA                                                      #
#                                                                         #
###########################################################################


import sys
import re
from elementtree.ElementTree import ElementTree, Element, SubElement, dump, parse

if len(sys.argv) < 3:
   print sys.argv[0] + " inputfile outputfile"
   sys.exit(1)
data = open(sys.argv[1],'r')

kml_root = Element("kml")
kml_root.set("xmlns","http://earth.google.com/kml/2.0")

kml_doc = SubElement(kml_root,"Document")
kml_docname = SubElement(kml_doc,"name")

kml_docname.text = raw_input("Inserire il nome da dare al documento KML: ")

kml_folder = SubElement(kml_doc,"Folder")
kml_foldername = SubElement(kml_folder,"name")
kml_foldername.text = raw_input("Inserire il nome dell'insieme di punti rilevati: ")
coordinates = str()
for txtline in data.readlines():
   trackopen = re.search('type="track" name="(?P<name>[^"]+)"', txtline)
   trackpoint = re.search('type="trackpoint"\s+altitude="(?P<alt>[^"]+)"\s+latitude="(?P<lat>[^"]+)"\s+longitude="(?P<lon>[^"]+)"', txtline)
   trackend = re.search('type="trackend"', txtline)
   
开发者ID:denever,项目名称:gpspoint2kml,代码行数:32,代码来源:route2kml.py

示例7: main

# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import set [as 别名]
def main(argv):

    scale = 1.0
    pathToCSV = ""
    forceHRM = False
    removePauses = False
    sport = "Running"
    lat = 0.0
    longt = 0.0
    ylat = 37.337766
    ylong = -121.920347

    try:
        opts, args = getopt.getopt(argv, "hbpYs:i:t:l:",["scale=", "ifile=", "sport=", "location="])
    except getopt.GetoptError:
        usage()
        sys.exit(1)

    for opt, arg in opts:
        if opt == '-h':
            usage()
            sys.exit()
        elif opt in ("-s", "--scale"):
            scale = float(arg)
        elif opt in ("-i", "--ifile"):
            pathToCSV = arg
        elif opt in ("-t", "--sport"):
            sport = arg
        elif opt in ("-l", "--location"):
            lat, longt = arg.split(",")
            lat = float(lat)
            longt = float(longt)
        elif opt == '-Y':
            lat = ylat
            longt = ylong
        elif opt == '-b':
            forceHRM = True
        elif opt == '-p':
            removePauses = True
        
    if pathToCSV == "":
        usage()
        sys.exit(1) 
    
    f = open(pathToCSV)
    dataDict = csv.DictReader(f)
    intensity = "Resting"
    triggerMethod = "Distance"

    tcxTrackpoints = {}
    earliestEpochMS = earliestTimeInDict(dataDict)
    earliestEpoch = math.floor(int(earliestEpochMS) / 1000)

    root = Element("TrainingCenterDatabase")
    root.set("xsi:schemaLocation", "http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2 http://www.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd")
    root.set("xmlns:ns2", "http://www.garmin.com/xmlschemas/UserProfile/v2")
    root.set("xmlns:ns3", "http://www.garmin.com/xmlschemas/ActivityExtension/v2")
    root.set("xmlns:ns4", "http://www.garmin.com/xmlschemas/ProfileExtension/v1")
    root.set("xmlns:ns5", "http://www.garmin.com/xmlschemas/ActivityGoals/v1")
    root.set("xmlns", "http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2")
    root.set("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")

    actsElement = SubElement(root, "Activities")
    actElement = SubElement(actsElement, "Activity", Sport=sport)

    idElement = SubElement(actElement, "Id")
    idElement.text = stringGMTimeFromEpoch(earliestEpoch)

    lastTimeEpoch = 0
    
    lapElement = SubElement(actElement, "Lap", StartTime=stringGMTimeFromEpoch(earliestEpoch))
    
    totalDistanceMeters = 0
    maxSpeed = 0
    calories = 0.0
    maxBPM = 0    
    maxSpeed = 0.0
    numRows = 0
    totalBPM = 0
    epochStart = 0
    diff = 0
    
    trackpoints = list()
    
    for row in dataDict:
        speed = scale * float(row['SPEED'])
        stepRate = int(row['STEP_RATE'])
        mCadence = int(row['CADENCE'])

        if speed > maxSpeed:
            maxSpeed = speed

        if not removePauses or (speed > 0 and stepRate > 0):
            if epochStart != 0:
                diff += int(row['timestamp_epoch']) - epochStart
                epochStart = 0

            trackpointElement = Element("Trackpoint")
            trackpoints.append(trackpointElement)
        
#.........这里部分代码省略.........
开发者ID:fifors,项目名称:MotoACTV-tcx,代码行数:103,代码来源:motoactv_tcx.py

示例8: addLangs

# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import set [as 别名]
 def addLangs(self, element, msg):
     for lang in self.all_languages:
         elem = Element(NS + 'langstring')
         elem.set('language', lang)
         elem.text = msg
         element.append(elem)
开发者ID:EU-OSHA,项目名称:osha.policy,代码行数:8,代码来源:vdexupdater.py


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