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


Python ElementTree.write方法代码示例

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


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

示例1: tweak_build_xml

# 需要导入模块: from xml.etree.cElementTree import ElementTree [as 别名]
# 或者: from xml.etree.cElementTree.ElementTree import write [as 别名]
    def tweak_build_xml(self):
        runjdwp_args = [
            'transport=dt_socket',
            'server=y',
            'address=8765',
            'suspend=n',
        ]
        runjdwp_args = ','.join(runjdwp_args)
        jvm_debug_args = [
            '-Xdebug',
            '-Xrunjdwp:%s' % (runjdwp_args,),
        ]
        jvm_debug_args = ' '.join(jvm_debug_args)

        build_xml = self.get_build_xml()
        tree = ElementTree()
        tree.parse(build_xml)

        root = tree.getroot()
        targets = root.findall('target')
        for node in targets:
            if node.get('name') == 'run':
                java_node = node.find('java')
                SubElement(java_node, 'jvmarg', {
                    'line': jvm_debug_args,
                })
        tree.write(build_xml)
开发者ID:asorici,项目名称:JaCaMo-R-Landri,代码行数:29,代码来源:sandbox.py

示例2: exportGEXF

# 需要导入模块: from xml.etree.cElementTree import ElementTree [as 别名]
# 或者: from xml.etree.cElementTree.ElementTree import write [as 别名]
    def exportGEXF(self, fileName):
        rootNode = Element("gexf")
        rootNode.attrib['xmlns'] = "http://www.gexf.net/1.2draft"
        rootNode.attrib['version'] = "1.2"

        graphNode = Element("graph")
        graphNode.attrib['mode'] = "static"
        graphNode.attrib['defaultedgetype'] = "directed"
        rootNode.append(graphNode)

        graphNode.append(Node.getGexfAttributeNode())
        graphNode.append(Vertex.getGexfAttributeNode())

        NodesList = Element("nodes")
        for n in self.nodes:
            NodesList.append(n.exportToGexfNode())
        graphNode.append(NodesList)

        EdgesList = Element("edges")
        for e in self.vertices:
            EdgesList.append(e.exportToGexfNode())
        graphNode.append(EdgesList)

        doc = ElementTree(rootNode)
        doc.write(fileName, "utf8", '<?xml version="1.0" encoding="UTF-8"?>')
开发者ID:Noxy,项目名称:callGraphAnalysis,代码行数:27,代码来源:first_try_program.py

示例3: write

# 需要导入模块: from xml.etree.cElementTree import ElementTree [as 别名]
# 或者: from xml.etree.cElementTree.ElementTree import write [as 别名]
	def write(self, filename, midi):
		

		midifile = Element('MidiFile')
		header = HeaderChunk()
		
		header.write(midifile, midi.header)

		i = 0
		for cur in midi.tracks:
			node = SubElement(midifile, '_' + str(i)) #garantit l'ordre des datas
			temp = TrackChunk()
			temp.write(node, cur)
			i += 1

		tree = ElementTree(midifile)
		tree.write(filename, encoding="utf-8")

		

		import xml.dom.minidom 

		root = xml.dom.minidom.parse(filename)

		f = open(filename, "w")
		f.write(root.toprettyxml())
开发者ID:Eyyub,项目名称:midi,代码行数:28,代码来源:ixml.py

示例4: test_3x32mb_download_from_xml

# 需要导入模块: from xml.etree.cElementTree import ElementTree [as 别名]
# 或者: from xml.etree.cElementTree.ElementTree import write [as 别名]
    def test_3x32mb_download_from_xml(self):
        '''Download three randomly-generated 32MB files from a GT server
           via an XML manifest'''
        uuid1 = self.data_upload_test(1024 * 1024 * 32)
        uuid2 = self.data_upload_test(1024 * 1024 * 32)
        uuid3 = self.data_upload_test(1024 * 1024 * 32)

        uuids = [uuid1, uuid2, uuid3]

        # build a XML result set
        result_set = Element('ResultSet')
        result_1 = SubElement(result_set, 'Result')
        analysis_data_uri_1 = SubElement(result_1, 'analysis_data_uri')
        analysis_data_uri_1.text = '%s/cghub/data/analysis/download/' \
            % TestConfig.HUB_SERVER + str(uuid1)
        result_2 = SubElement(result_set, 'Result')
        analysis_data_uri_2 = SubElement(result_2, 'analysis_data_uri')
        analysis_data_uri_2.text = '%s/cghub/data/analysis/download/' \
            % TestConfig.HUB_SERVER + str(uuid2)
        result_3 = SubElement(result_set, 'Result')
        analysis_data_uri_3 = SubElement(result_3, 'analysis_data_uri')
        analysis_data_uri_3.text = '%s/cghub/data/analysis/download/' \
            % TestConfig.HUB_SERVER + str(uuid3)

        doc = ElementTree(result_set)

        f = NamedTemporaryFile(delete=False, suffix='.xml')
        doc.write(f)
        f.close()

        self.data_download_test_xml(f.name, uuids)

        os.remove(f.name)
开发者ID:hammer,项目名称:genetorrent,代码行数:35,代码来源:gt_download_tests.py

示例5: serialize

# 需要导入模块: from xml.etree.cElementTree import ElementTree [as 别名]
# 或者: from xml.etree.cElementTree.ElementTree import write [as 别名]
def serialize(data, name='object'):
    content_elem = Element(name)
    _serialize(content_elem, data)
    tree = ElementTree(content_elem)
    f = StringIO()
    tree.write(f, 'UTF-8')
    return f.getvalue()
开发者ID:BenoitTalbot,项目名称:bungeni-portal,代码行数:9,代码来源:serialize.py

示例6: extractImages

# 需要导入模块: from xml.etree.cElementTree import ElementTree [as 别名]
# 或者: from xml.etree.cElementTree.ElementTree import write [as 别名]
def extractImages(html):
    if html is None:
        return [], html
    
    tree = ElementTree()
    tree.parse(StringIO(html))
    imagetags = tree.findall(".//img")
    
    images = []
    for tag in imagetags:
        image = tag.get('src')
        path, name = os.path.split(image)
        if image not in images:
            images.append(image)
        tag.set('alt', name)
        tag.set('title', name)

    #index files for multipart storage
    index = {}
    for image in images:
        path, name = os.path.split(image)        
        index[image] = '0x%08x' % binascii.crc32(name)

    #update html email image tags 
    for tag in imagetags:
        image = tag.get('src')
        tag.set('src', "cid:%s" % index[image])
            
    html =  StringIO()
    tree.write(html)
    html.write("\n")
    return [index, html.getvalue()]
开发者ID:robertbetts,项目名称:Kew,代码行数:34,代码来源:emailutil.py

示例7: edx

# 需要导入模块: from xml.etree.cElementTree import ElementTree [as 别名]
# 或者: from xml.etree.cElementTree.ElementTree import write [as 别名]
    def edx(self, out_dir):
        # Copy the image to the static directory
        static_dir = os.path.join(out_dir, 'static')
        if not os.path.exists(static_dir):
            os.makedirs(static_dir)
        # In order to get an unique filename inside edx, we have to prefix the project and group name
        # We cannot use the filename, because it may contain characters, that have to be escaped.
        # Therefore we just add the extension, which is expected to contain [a-z][A-Z][0-9].
        _, fileExtension = os.path.splitext(self.path)
        target_filename = self.url_name()+fileExtension
        target_path = os.path.join(static_dir,target_filename)
        shutil.copyfile(os.path.join(self.parent.path, self.path), target_path);

        html_dir = os.path.join(out_dir, 'html')
        if not os.path.exists(html_dir):
            os.makedirs(html_dir)
        html = Element('html', {'filename':self.url_name(), 'display_name':"Img"});
        tree = ElementTree(html)
        tree.write(os.path.join(html_dir, "{0}.xml".format(self.url_name())) )

        # We have to double %% because % is a placeholder for the argument
        html = '<img src="/static/%(file)s">' % {'file':target_filename}
        
        html += '''<br>
        <a href="/static/%(file)s">Download Image %(name)s</a>
        ''' % {'file':target_filename, 'name':os.path.basename(self.path)}

        with codecs.open(os.path.join(html_dir, "{0}.html".format(self.url_name())), mode='w', encoding='utf-8') as f:
            f.write(html)
开发者ID:pdehaye,项目名称:edx-presenter,代码行数:31,代码来源:mat101-presenter.py

示例8: merge

# 需要导入模块: from xml.etree.cElementTree import ElementTree [as 别名]
# 或者: from xml.etree.cElementTree.ElementTree import write [as 别名]
    def merge(self):
        last_hr = 0
        self.tacx_tcx = self._parse_file(self.tacx_tcx_file)
        self.hr_tcx = self._parse_file(self.hr_tcx_file)

        for tp in self.tacx_tcx.dom_trackpoints:
            timestamp = tp.find('role:Time', ns).text
            timestamp_key = timestamp[0:19]
            if timestamp_key in self.hr_tcx.TrackPoints.keys():
                heartrate_from_other_file = self.hr_tcx.TrackPoints[timestamp_key].HeartRateBpm
                if heartrate_from_other_file is not None:
                    hr_node = self._create_heartrate(heartrate_from_other_file)
                    tp.append(hr_node)
                    last_hr = heartrate_from_other_file
            else:
                hr_node = self._create_heartrate(last_hr)
                tp.append(hr_node)

        tree = ElementTree(self.tacx_tcx.root)

        tree.write(open(self.file_name, 'wb'), encoding="utf-8", xml_declaration=True)

        # Add UGLY! temporary fix for namespace "ns1-issue"
        f = open (self.file_name, "r")
        data = f.read()
        data = data.replace('ns1:TPX', 'TPX')
        data = data.replace('ns1:Speed', 'Speed')
        data = data.replace('ns1:Watts', 'Watts')
        f.close

        f = open(self.file_name, "w")
        f.write(data)
        f.close()
        return self.file_name
开发者ID:trieb,项目名称:merge_tcx,代码行数:36,代码来源:MergeTcx.py

示例9: dump

# 需要导入模块: from xml.etree.cElementTree import ElementTree [as 别名]
# 或者: from xml.etree.cElementTree.ElementTree import write [as 别名]
 def dump(self, stream):
     if self.prettyprint:
         self.indent(self.xml)
     document = ElementTree(self.xml)
     header='<?xml version="1.0" encoding="%s"?>'%self.encoding
     stream.write(header.encode(self.encoding))
     document.write(stream, encoding=self.encoding)
开发者ID:biancini,项目名称:Rorschach-Test-Platform,代码行数:9,代码来源:graphml.py

示例10: _split_configuration

# 需要导入模块: from xml.etree.cElementTree import ElementTree [as 别名]
# 或者: from xml.etree.cElementTree.ElementTree import write [as 别名]
 def _split_configuration(self, projectfile, temp_dir):
     num_pieces = multiprocessing.cpu_count()
     tree = ET(file=unicode(projectfile))
     num_files = len(tree.findall('./files/file'))
     splitfiles = []
     files_per_job = int(math.ceil(float(num_files)/num_pieces))
     for idx in xrange(num_pieces):
         tree = ET(file=unicode(projectfile))
         root = tree.getroot()
         start = idx*files_per_job
         end = start + files_per_job
         if end > num_files:
             end = None
         for elem in ('files', 'images', 'pages',
                      'file-name-disambiguation'):
             elem_root = root.find(elem)
             to_keep = elem_root.getchildren()[start:end]
             to_remove = [x for x in elem_root.getchildren()
                          if not x in to_keep]
             for node in to_remove:
                 elem_root.remove(node)
         out_file = temp_dir / "{0}-{1}.ScanTailor".format(projectfile.stem,
                                                           idx)
         tree.write(unicode(out_file))
         splitfiles.append(out_file)
     return splitfiles
开发者ID:atomotic,项目名称:spreads,代码行数:28,代码来源:scantailor.py

示例11: main

# 需要导入模块: from xml.etree.cElementTree import ElementTree [as 别名]
# 或者: from xml.etree.cElementTree.ElementTree import write [as 别名]
def main():
    options, args = parse_args()
    rootElement = Element('packages')

    packages = {}

    print "Searching for packages.config files:"

    for dirpath, subdirs, filenames in walk('src'):
        for filename in filenames:
            if filename == 'packages.config':
                filepath = join(dirpath, filename)
                print "    " + filepath
                et = parse(filepath)
                for packageElement in et.findall('package'):
                    pkgId = packageElement.get('id')
                    pkgVersion = packageElement.get('version')
                    packages[pkgId, pkgVersion] = packageElement

    print
    print "Writing projectdata/packages.config:"
    rootElement.extend([value for (key,value) in sorted(packages.items())])
    indent(rootElement)
    tree = ElementTree(rootElement)
    dump(tree)
    tree.write('projectdata/packages.config')
开发者ID:DoomHammer,项目名称:ohdevtools,代码行数:28,代码来源:update-nuget.py

示例12: edx

# 需要导入模块: from xml.etree.cElementTree import ElementTree [as 别名]
# 或者: from xml.etree.cElementTree.ElementTree import write [as 别名]
	def edx(self, out_dir):
		discussion_dir = os.path.join(out_dir, 'discussion')
		if not os.path.exists(discussion_dir):
			os.makedirs(discussion_dir)
		discussion = Element('discussion', {'discussion_id':self.url_name()});
		tree = ElementTree(discussion)
		tree.write(os.path.join(discussion_dir, "{0}.xml".format(self.url_name())) )
开发者ID:UniversitatZurich,项目名称:edx-presenter,代码行数:9,代码来源:edx-presenter.py

示例13: build

# 需要导入模块: from xml.etree.cElementTree import ElementTree [as 别名]
# 或者: from xml.etree.cElementTree.ElementTree import write [as 别名]
def build():

	character_name = raw_input("What is the name of this character? -> ")

	tree = Element("conversation")

	stack = []

	prompts = []

	stack.append(tree)
	
	prompts.append("as a greeting? -> ");

	while (len(stack)>0):
		
		# the current node in the conversation
		conversation = stack.pop()
		
		prompt = prompts.pop()

		# add an ai_dialog section to the conversation
		dialog = raw_input("What does the character say " + prompt)

		if (len(dialog) == 0):
			continue

		ai_dialog = SubElement(conversation, "ai_dialog").text = dialog

		# determine how many dialog options the player has at this point
		how_many_options = int(raw_input('how many dialog options does the player have from "' + ai_dialog +'" -> '))
		
		# if there are dialog options...
		if (how_many_options > 0):

			# create a branch for player dialog options
			player_dialog_options = SubElement(conversation, "player_dialog_options")

			for i in range(how_many_options):

				# create a new choice
				choice = SubElement(player_dialog_options, "choice")

				# convert the dialog option number into ordinal form
				ordinal = lambda n: "%d%s" % (n,"tsnrhtdd"[(n/10%10!=1)*(n%10<4)*n%10::4])

				# add the player's reply 
				reply = raw_input("what is the player's " + ordinal(i+1) + ' response to "'  + ai_dialog +'" -> ')
				SubElement(choice, "reply").text = reply

				# add a new conversation as a child of the selected choice
				stack.append(SubElement(choice, "conversation"))
				prompts.append('to "' + reply +'" -> ')

	output = ElementTree(tree)

	# save the tree to an xml file in a local directory named after the character
	path = os.path.dirname(os.path.realpath(__file__))+"/character-dialogs/"+character_name+"_conversation.xml"
	output.write(path)
开发者ID:claytonpeterson,项目名称:dialog-to-xml,代码行数:61,代码来源:run.py

示例14: write

# 需要导入模块: from xml.etree.cElementTree import ElementTree [as 别名]
# 或者: from xml.etree.cElementTree.ElementTree import write [as 别名]
    def write(self, file):
        """
        write(file) -> None

        Write XML to filename of file object in 'file'
        """
        et = ElementTree(self.root)
        et.write(file)
开发者ID:GNOME,项目名称:ontv,代码行数:10,代码来源:xmltv.py

示例15: serialize

# 需要导入模块: from xml.etree.cElementTree import ElementTree [as 别名]
# 或者: from xml.etree.cElementTree.ElementTree import write [as 别名]
def serialize(data, name='object'):
    content_elem = Element('contenttype')
    content_elem.attrib['name'] = name 
    _serialize(content_elem, data)
    tree = ElementTree(content_elem)
    f = StringIO()
    tree.write(f, 'UTF-8')
    return f.getvalue()
开发者ID:BenoitTalbot,项目名称:bungeni-portal,代码行数:10,代码来源:serialize.py


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