本文整理汇总了Python中elementtree.ElementTree.SubElement.text方法的典型用法代码示例。如果您正苦于以下问题:Python SubElement.text方法的具体用法?Python SubElement.text怎么用?Python SubElement.text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类elementtree.ElementTree.SubElement
的用法示例。
在下文中一共展示了SubElement.text方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _ConvertModelPerformance
# 需要导入模块: from elementtree.ElementTree import SubElement [as 别名]
# 或者: from elementtree.ElementTree.SubElement import text [as 别名]
def _ConvertModelPerformance(perf,modelPerf):
if len(modelPerf)>3:
confMat = modelPerf[3]
accum = 0
for row in confMat:
for entry in row:
accum += entry
accum = str(accum)
else:
confMat = None
accum = 'N/A'
if len(modelPerf)>4:
elem = SubElement(perf,"ScreenThreshold")
elem.text=str(modelPerf[4])
elem = SubElement(perf,"NumScreened")
elem.text=accum
if len(modelPerf)>4:
elem = SubElement(perf,"NumSkipped")
elem.text=str(modelPerf[6])
elem = SubElement(perf,"Accuracy")
elem.text=str(modelPerf[0])
elem = SubElement(perf,"AvgCorrectConf")
elem.text=str(modelPerf[1])
elem = SubElement(perf,"AvgIncorrectConf")
elem.text=str(modelPerf[2])
if len(modelPerf)>4:
elem = SubElement(perf,"AvgSkipConf")
elem.text=str(modelPerf[5])
if confMat:
elem = SubElement(perf,"ConfusionMatrix")
elem.text = str(confMat)
示例2: createFilePodcast
# 需要导入模块: from elementtree.ElementTree import SubElement [as 别名]
# 或者: from elementtree.ElementTree.SubElement import text [as 别名]
def createFilePodcast(mediaFilePath, title, description=''):
"""
create the xml file using utf
"""
mediaItem = Element("media")
mediaItem.attrib["version"] = VERSION
titleNode = SubElement(mediaItem, "title")
titleNode.text = title
descrNode = SubElement(mediaItem, "description")
descrNode.text = description
createXmlFile(mediaFilePath + '.xml', mediaItem)
mediaItem.clear()
示例3: TextElement
# 需要导入模块: from elementtree.ElementTree import SubElement [as 别名]
# 或者: from elementtree.ElementTree.SubElement import text [as 别名]
def TextElement(root, name, detail_value):
if detail_value:
te = SubElement(root, name)
if detail_value.type == "text/html": detail_value.type = "html"
if detail_value.type == "text/plain": detail_value.type = "text"
te.attrib["type"] = detail_value.type
te.text = detail_value.value
示例4: toElementTree
# 需要导入模块: from elementtree.ElementTree import SubElement [as 别名]
# 或者: from elementtree.ElementTree.SubElement import text [as 别名]
def toElementTree(self, details):
"""
Return an Element node with the XML rappresentation of this module
"""
c = Element('module')
n = SubElement(c, 'name')
n.text = self._alias
if details:
# version
v = SubElement(c, 'version')
v.text = str(self._version)
# type
t = SubElement(c, 'type')
t.text = self._type
# lock
u = SubElement(c, 'upgradable')
u.text = repr(self._upgradable).lower()
return c
示例5: addRing
# 需要导入模块: from elementtree.ElementTree import SubElement [as 别名]
# 或者: from elementtree.ElementTree.SubElement import text [as 别名]
def addRing(self, objRing, strType):
if strType == 'Inner':
elemBnd = Element('innerBoundaryIs')
else:
elemBnd = Element('outerBoundaryIs')
elemRing = SubElement(elemBnd, 'LinearRing')
elemCoords = SubElement(elemRing, "coordinates")
elemCoords.text = self.addCoordinates(objRing[1])
return elemBnd
示例6: addGraphonesToLexicon
# 需要导入模块: from elementtree.ElementTree import SubElement [as 别名]
# 或者: from elementtree.ElementTree.SubElement import text [as 别名]
def addGraphonesToLexicon(xml, graphones):
lexicon = xml.getroot()
for letters, phonemes in graphones:
lemma = SubElement(lexicon, 'lemma')
lemma.text = '\n '
orth = SubElement(lemma, 'orth')
orth.text = '_' + ''.join(letters) + '_'
orth.tail = '\n '
phon = SubElement(lemma, 'phon')
phon.text = ' '.join(phonemes)
phon.tail = '\n '
synt = SubElement(lemma, 'synt')
SubElement(synt, 'tok').text = lmToken(letters, phonemes)
synt.tail = '\n'
# synt.tail = '\n '
# eval = SubElement(lemma, 'eval')
# SubElement(eval, 'tok').text = '[UNKNOWN]'
# eval.tail = '\n'
lemma.tail = '\n'
示例7: GetFeedElement
# 需要导入模块: from elementtree.ElementTree import SubElement [as 别名]
# 或者: from elementtree.ElementTree.SubElement import text [as 别名]
def GetFeedElement(feed):
"""Create an atom:feed element for the provided feed.
The provided feed must be in the format described at http://feedparser.org.
"""
rss = Element("rss")
rss.attrib["version"] = "2.0"
root = SubElement(rss, "channel")
TextElement(root, "title", feed.feed.get("title_detail"))
if feed.feed.has_key("links"):
for link in feed.feed.links:
if link.rel != "self": continue
SubElementIf(root, "link", link.href)
TextElement(root, "description", feed.feed.get("subtitle_detail"))
TextElement(root, "copyright", feed.feed.get("rights_detail"))
SubElement(root, "generator").text = "feedarchive"
if feed.feed.has_key("image"):
im = feed.feed.image
ie = SubElement(root, "image")
SubElementIf(ie, "url", im.get("href"))
SubElementIf(ie, "title", im.get("title"))
SubElementIf(ie, "link", im.get("link"))
if feed.feed.has_key("tags"):
for tag in feed.feed.tags:
te = SubElement(root, "category")
if (tag.has_key("scheme")): te.attrib["domain"] = tag.scheme
te.text = tag.term
for entry in feed.entries:
ee = SubElement(root, "item")
TextElement(ee, "title", entry.get("title_detail"))
SubElementIf(ee, "link", entry.get("link"))
TextElement(ee, "description", entry.get("summary_detail"))
SubElementIf(ee, "guid", entry.get("id"))
DateTimeElement(ee, "pubDate", entry, "published")
PersonElement(ee, "author", entry.get("author_detail"))
if entry.has_key("links"):
for link in entry.links:
if link.rel != "enclosure": continue
ence = SubElement(ee, "enclosure")
AttribIf(ence, "url", link.get("url"))
AttribIf(ence, "length", link.get("length"))
AttribIf(ence, "type", link.get("type"))
return rss
示例8: __init__
# 需要导入模块: from elementtree.ElementTree import SubElement [as 别名]
# 或者: from elementtree.ElementTree.SubElement import text [as 别名]
def __init__(self, lstData, GeoType, strPath, strFilename, strLayername):
dctWriteKML = {'Point': self.writePoint, 'Polyline': self.writeLine, 'Polygon': self.writePolygon}
#Create new element tree with a root of KML...
objRoot = Element("{http://earth.google.com/kml/2.1}kml")
objTree = ElementTree(element=objRoot)
elemDoc = SubElement(objRoot, 'Document')
elemDocName = SubElement(elemDoc, 'name')
#According the KML spec, default Polystyle stuff goes here...
elemDocName.text = strLayername
#Add a document name element here...populate from supplied parameters
for objRow in lstData:
elemPlace = SubElement(elemDoc, 'Placemark')
elemName =SubElement(elemPlace,'name')
elemName.text = objRow['Name']
#Add support for the description tag...
elemDesc = SubElement(elemPlace, 'description')
elemDesc.text = objRow['Description']
elemGeo = dctWriteKML.get(GeoType, self.errHandler)(objRow['Geometry'], elemPlace)
elemPlace.append(elemGeo)
self.Write(objTree, strPath, strFilename)
示例9: ToElement
# 需要导入模块: from elementtree.ElementTree import SubElement [as 别名]
# 或者: from elementtree.ElementTree.SubElement import text [as 别名]
def ToElement(self):
"""
Gets an ElementTree.Element representation.
"""
peer = self.peer
elt = Element("entity", id=peer.id_)
SubElement(elt, "address").text = peer.address.ToString()
SubElement(elt, "version").text = str(peer.protocol_version)
hist = SubElement(elt, "history")
keys = self.intervals.keys()
keys.sort()
for k in keys:
c = SubElement(hist, "connected")
i = self.intervals[k]
c.text = "%s-%s" % (i.start, i.end)
return elt
示例10: add_work_unit_to_task
# 需要导入模块: from elementtree.ElementTree import SubElement [as 别名]
# 或者: from elementtree.ElementTree.SubElement import text [as 别名]
def add_work_unit_to_task(tree_root, task_name_or_id):
"""Adds a work unit to the specified task. If the task is not
active, the operation throws Active_error."""
# Obtain the task id.
node = find_task(tree_root, task_name_or_id)
task_id = node.find("id").text
# If the task is killed, report it.
if node.get("killed") == "yes":
raise Active_error("Task %s is dead, aborting "
"operation." % task_name_or_id)
# Create a work-unit for the found task.
work_units = tree_root.find("work-unit-list")
work_unit = SubElement(work_units, "work-unit")
work_unit.set("id", task_id)
work_unit.text = get_today()
示例11: recurse_for_children
# 需要导入模块: from elementtree.ElementTree import SubElement [as 别名]
# 或者: from elementtree.ElementTree.SubElement import text [as 别名]
def recurse_for_children(current_node, parent_node, active_cat, show_empty=True):
child_count = current_node.child.count()
if show_empty or child_count > 0 or current_node.product_set.count() > 0:
temp_parent = SubElement(parent_node, 'li')
attrs = {'href': current_node.get_absolute_url()}
if current_node == active_cat:
attrs["class"] = "current"
if current_node.parent:
link = SubElement(temp_parent, 'a', attrs)
else:
link = SubElement(temp_parent, 'span', {})
link.text = current_node.name
if child_count > 0:
new_parent = SubElement(temp_parent, 'ul')
children = current_node.child.all()
for child in children:
recurse_for_children(child, new_parent, active_cat)
示例12: add_task
# 需要导入模块: from elementtree.ElementTree import SubElement [as 别名]
# 或者: from elementtree.ElementTree.SubElement import text [as 别名]
def add_task(tree_root, task_name):
"""Adds (stripped) task_name to the tree_root."""
assert task_name == task_name.strip()
assert len(task_name) > 1
# Get a new task id, higher than all previous ones.
id_num = highest_task_id(tree_root) + 1
assert id_num >= 0
# Create the task.
tasklist = tree_root.find("task-list")
task = SubElement(tasklist, "task")
SubElement(task, "id").text = "%d" % id_num
SubElement(task, "name").text = task_name.strip()
date_today = get_today()
SubElement(task, "starting-day").text = date_today
SubElement(task, "note").text = ""
last_unit = SubElement(task, "last-unit", attrib = {"amount": "0"})
last_unit.text = date_today
示例13: create_empty_configuration_file
# 需要导入模块: from elementtree.ElementTree import SubElement [as 别名]
# 或者: from elementtree.ElementTree.SubElement import text [as 别名]
def create_empty_configuration_file(file_name):
"""Creates a default empty file with today's date as starting day."""
root = Element("frequent-task-reminder")
# Create the configuration element.
config = SubElement(root, "configuration")
# Set the first day to track as today.
start = SubElement(config, "starting-day")
start.text = time.asctime()
# Create a default empty task.
tasklist = SubElement(root, "tasklist")
task = SubElement(tasklist, "task")
SubElement(task, "id").text = 0
SubElement(task, "name").text = "Default name"
SubElement(task, "notes").text = "Some random notes you can modify."
# Finally write the xml file.
ElementTree(root).write(file_name, encoding="latin1")
print "Created empty configuration file '%s'." % file_name
示例14: TextElement
# 需要导入模块: from elementtree.ElementTree import SubElement [as 别名]
# 或者: from elementtree.ElementTree.SubElement import text [as 别名]
def TextElement(root, name, detail_value):
if detail_value:
te = SubElement(root, name)
te.text = detail_value.value
示例15: len
# 需要导入模块: from elementtree.ElementTree import SubElement [as 别名]
# 或者: from elementtree.ElementTree.SubElement import text [as 别名]
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)
if trackopen:
kml_placemark = SubElement(kml_folder,"Placemark")
kml_placemark_desc = SubElement(kml_placemark, "description")
kml_placemark_desc.text = raw_input("Inserire descrizione per il percorso di nome '"+trackopen.group('name')+"': ")
kml_placemark_name = SubElement(kml_placemark,"name")