As nathanr said, there aren’t many (any?) Python macro examples around. Below is one that I wrote based on some code I found a while ago. This code automates some edits in the active edit window. Maybe you can get some ideas from it that are useful. The quotes and commas should be removed - they are there because I copied the code from an archive .komodotool file.
rod
"import eollib",
"from xpcom import components",
"",
"viewSvc = components.classes[\"@activestate.com/koViewService;1\"].getService(components.interfaces.koIViewService)",
"view = viewSvc.currentView",
"view = view.queryInterface(components.interfaces.koIScintillaView)",
"sm = view.scimoz",
"",
"wwatch = components.classes[\"@mozilla.org/embedcomp/window-watcher;1\"].getService(components.interfaces.nsIWindowWatcher)",
"prompt = wwatch.getNewPrompter(wwatch.activeWindow)",
"",
"# get cursor position",
"curs1 = sm.currentPos",
"",
"# copy buffer",
"sel1 = sm.setSel(1,5)",
"sm.documentStartExtend()",
"sm.documentEndExtend()",
"start = sm.positionFromLine(sm.lineFromPosition(sm.selectionStart))",
"end = sm.getLineEndPosition(sm.lineFromPosition(sm.selectionEnd))",
"mod1v = sm.getTextRange(start,end).splitlines()",
"#prompt.alert(\"length\", str(len(mod1v)))",
"",
"# modify section lines",
"mod2v=[]",
"idx = 0",
"for ln in mod1v:",
" if ln[0:3] == '[s]' :",
" idx += 1",
" ln = str(idx).zfill(2) + ln",
" #prompt.alert(\"section\", ln)",
" mod2v.append(ln)",
"",
"# replace buffer",
"sm.setSel(start,end)",
"eol = eollib.eol2eolStr[sm.eOLMode] ",
"sm.replaceSel(eol.join(mod2v))",
"",
"sm.gotoPos(curs1)"