本文整理匯總了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