Created
January 24, 2021 14:29
-
-
Save jedrekk/dcba17e11369bf6f4c053156091db660 to your computer and use it in GitHub Desktop.
Converts rem to em units, multiplying them by 1.6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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