Split with regex
examples/regex/field_value_pairs.txt
fname = Foo lname = Bar email=foo@bar.com
examples/regex/parse_field_value_pairs.py
import sys import re # data: field_value_pairs.txt if len(sys.argv) != 2: exit(f"Usage: {sys.argv[0]} filename") filename = sys.argv[1] with open(filename) as fh: for line in fh: line = line.rstrip("\n") field, value = re.split(r'\s*=\s*', line) print(f"{value}={field}")
Foo=fname Bar=lname foo@bar.com=email