Skip to main content
2 / 4
本文から 9 文字削除
metropolis
  • 6,705
  • 2
  • 6
  • 16
import re
import io

text = '''
test login_id: userid
authority: root folder: root123
login password: 1234***
'''.lstrip()

data = []
for l in io.StringIO(text):
    data += [{k: v} for k, v in re.findall(r'\s*(.+?):\s+([^\s]+)', l)]

print(data)

# [{'test login_id': 'userid'}, {'authority': 'root'}, {'folder': 'root123'}, {'login password': '1234***'}]
metropolis
  • 6,705
  • 2
  • 6
  • 16