Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
正規表現を使用してファイルを解析しようとしていXMLます (私の場合、これが最も簡単な方法のようです)。
XML
たとえば、行は次のようになります。
line='<City_State>PLAINSBORO, NJ 08536-1906</City_State>'
タグ City_State のテキストにアクセスするには、次を使用しています。
attr = re.match('>.*<', line)
しかし、何も返されていません。
誰かが私が間違っていることを指摘できますか?
ElementTree のような XML パーサーを使用してください。
>>> from xml.etree import ElementTree as ET >>> line='<City_State>PLAINSBORO, NJ 08536-1906</City_State>' >>> ET.fromstring(line).text 'PLAINSBORO, NJ 08536-1906'