replace-features.py
698 Bytes
import argparse
from data import read_file, index_by_id, write_line
# -- ARGPARSE
parser = argparse.ArgumentParser(
description="Replace features with file from to file to")
parser.add_argument("fromfile", type=str, help="From list or features file")
parser.add_argument("tofile", type=str, help="Features of 'from' saved into this file.")
args = parser.parse_args()
FROM = args.fromfile
TO = args.tofile
# -- READ AND INDEX FILES
from_data = read_file(FROM)
from_by_id = index_by_id(from_data)
to_data = read_file(TO)
with open(TO, "w") as f:
for line in to_data:
metas = line[0]
features = from_by_id[metas[0]][metas[3]][1]
write_line(metas, features, f)