Skip to content

Instantly share code, notes, and snippets.

@Mark24Code
Created June 30, 2017 09:06
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 Mark24Code/d919559feffe5074541250942a411d0c to your computer and use it in GitHub Desktop.
Save Mark24Code/d919559feffe5074541250942a411d0c to your computer and use it in GitHub Desktop.
px2rem.py
import re
newlines = []
with open('ff','r',encoding='UTF-8') as f:
lines = f.readlines()
for line in lines:
m = re.search(r'.+: (\d.px).+',line)
newline = ''
if m:
print(m.group(0))
print(m.group(1))
pxword = m.group(1)
break_lines_arr = line.split(pxword)
new_pxword = 'rem({})'.format(pxword)
break_lines_arr.insert(1, new_pxword)
newline = ''.join(break_lines_arr)
newlines.append( newline if m else line)
nf = open('new_scss.scss','w')
nf.writelines(newlines)
nf.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment