Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- import sys, os, re
- from collections import namedtuple
- Macro = namedtuple('Macro', ['nev','ertek'])
- Kifejezes = namedtuple('Kifejezes', ['nev', 'kif'])
- macrok = []
- text = []
- try:
- isfile = os.path.isfile(sys.argv[1])
- except IndexError:
- print "Adj meg egy file-t!"
- exit()
- try:
- with open(sys.argv[1],'r') as f:
- for s in f:
- match = re.match(r'#::(.*)', s)
- if match:
- macro = Macro(*match.group(1).strip().split())
- macrok.append(macro)
- else:
- text.append(s)
- except IOError:
- print "Nincs ilyen file!"
- exit()
- for macro in macrok:
- for i, s in enumerate(text):
- if macro.nev in s:
- text[i] = re.sub(macro.nev, macro.ertek, s)
- with open(sys.argv[1].split('.')[0] + '_out.py', 'w') as f:
- for s in text:
- f.write(s)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement