Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Split with regex

fname    =    Foo
lname    = Bar
email=foo@bar.com
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