Skip to content

Instantly share code, notes, and snippets.

@jedrekk
Created January 24, 2021 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jedrekk/dcba17e11369bf6f4c053156091db660 to your computer and use it in GitHub Desktop.
Save jedrekk/dcba17e11369bf6f4c053156091db660 to your computer and use it in GitHub Desktop.
Converts rem to em units, multiplying them by 1.6
#!/usr/bin/python3
import sys
import re
from decimal import Decimal
file_name = sys.argv[1]
file = open(file_name)
lines = file.read()
file.close()
rems = re.findall(r'([0-9\.]+)rem', lines)
replace_list = []
for rem in rems:
em = Decimal(Decimal(rem) * Decimal(1.6)).quantize(Decimal('0.1'))
replace_list.append(("{}{}".format(rem, 'rem'), "{}{}".format(em, 'em')))
for item in replace_list:
lines = re.sub(item[0], item[1], lines)
with open(file_name, 'w') as f:
f.write(lines)
print("Converted: {}\n".format(file_name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment