Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- SRC = 'no event manager applet test\nevent manager applet test\n event none\n action 1010 if 1 eq 1\n action 1020 set i 1\n action 1030 end\n! end_applet\n'
- NO_APPLET = ''
- LABEL = '^ action \d{4}'
- LABEL_START = 10
- LABEL_STEP = 10
- print(SRC)
- dst = ''
- label = LABEL_START
- repl = ' action ' + '{:04d}'.format(label)
- # repl = 'action ' + str(label)
- # prog = re.compile(LABEL)
- # result = prog.match(string)
- for line in SRC.splitlines():
- newline, i = re.subn(LABEL, repl, line)
- # re.subn(pattern, repl, string, count=0, flags=0)
- if i > 0:
- label = label + LABEL_STEP
- # repl = ' action ' + format('{%4d}', label)
- repl = ' action ' + '{:04d}'.format(label)
- # repl = 'action ' + str(label)
- dst = dst + newline + '\n'
- print(dst)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement