Skip to content

Instantly share code, notes, and snippets.

@mijo-gracanin
Created February 2, 2022 14:53
Show Gist options
  • Select an option

  • Save mijo-gracanin/7d7b43532babc2097e2bf29f2e87fab8 to your computer and use it in GitHub Desktop.

Select an option

Save mijo-gracanin/7d7b43532babc2097e2bf29f2e87fab8 to your computer and use it in GitHub Desktop.
key_values_path = sys.argv[1]
text_path = sys.argv[2]
keys_and_values = ""
with open(key_values_path, 'r') as f:
keys_and_values = f.read()
text = ""
with open(text_path, 'r') as f:
text = f.read()
pattern = re.compile(r'(\w+)=(\w+)')
results = pattern.findall(keys_and_values)
old_for_new = dict()
for result in results:
old_for_new[result[0]] = result[1]
pattern = re.compile(r'(\w+)')
text = pattern.sub(lambda m: old_for_new[m.group()], text)
print(text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment