明らかに、私はPythonが初めてです。
以下のコードで StringIO を使用したいと思います: example.xml を抽出する
import os
os.chdir('d:/py/xml/')
from lxml import etree
from StringIO import StringIO
#----------------------------------------------------------------------
def parseXML(xmlFile):
"""
Parse the xml
"""
f = open(xmlFile)
xml = f.read()
f.close()
tree = etree.parse(StringIO(xml))
context = etree.iterparse(StringIO(xml))
for action, elem in context:
if not elem.text:
text = 'None'
else:
text = elem.text
print (elem.tag + ' => ' + text)
if __name__ == "__main__":
parseXML("example.xml")
しかし、私はこのメッセージを受け取り続けます
構文エラー: from io import import StringIO: d:\py\xml\example.py, line 621 File "d:\py\xml\example.py", line 6, in ? from io import import StringIO
私はグーグルで検索しましたが、ioモデルをインポートし、テキストまたはデータにio.StringIOまたはio.BytesIOを使用するように言われました...
誰か教えてください、どうすれば実際にそれを行うことができますか?
ありがとう