本文整理汇总了Python中System.IO.StringReader方法的典型用法代码示例。如果您正苦于以下问题:Python IO.StringReader方法的具体用法?Python IO.StringReader怎么用?Python IO.StringReader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO
的用法示例。
在下文中一共展示了IO.StringReader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: close
# 需要导入模块: from System import IO [as 别名]
# 或者: from System.IO import StringReader [as 别名]
def close(self):
"""Parse the XML from the internal buffer to build an
element tree.
Returns
-------
:class:`xml.etree.ElementTree.ElementTree`
The root element of the XML document
"""
xml_string = "".join(self._buffer)
self._buffer = None
reader = XmlReader.Create(StringReader(xml_string), self.settings)
while reader.Read():
if reader.IsStartElement():
self._start_element(reader)
elif reader.NodeType in [XmlNodeType.Text, XmlNodeType.CDATA]:
self._target.data(reader.Value.decode(self._document_encoding))
elif reader.NodeType == XmlNodeType.EndElement:
self._target.end(reader.LocalName)
elif reader.NodeType == XmlNodeType.XmlDeclaration:
self._parse_xml_declaration(reader.Value)
return self._target.close()
示例2: fromstring
# 需要导入模块: from System import IO [as 别名]
# 或者: from System.IO import StringReader [as 别名]
def fromstring(self, source):
return self.parse(StringReader(source))
示例3: GetLinesFromText
# 需要导入模块: from System import IO [as 别名]
# 或者: from System.IO import StringReader [as 别名]
def GetLinesFromText(text):
reader = StringReader(text)
lines = []
try:
line = reader.ReadLine()
while line is not None:
lines.append(line)
line = reader.ReadLine()
finally:
reader.Dispose()
return lines
示例4: ReadLinesFromText
# 需要导入模块: from System import IO [as 别名]
# 或者: from System.IO import StringReader [as 别名]
def ReadLinesFromText(text):
lines = []
with StringReader(text) as reader:
line = reader.ReadLine()
while line is not None:
lines.append(line)
line = reader.ReadLine()
return lines