Jose' Matos wrote: > On Wednesday 04 June 2003 13:45, Angus Leeming wrote: >> >> Not quite. If the second ExternalInset is of Template "Date" (no >> filename) then the result is >> \begin_inset External >> template Date >> filename taulogo.png >> >> where taulogo.png is filename from the first ExternalInset. >> >> Is there a filename.erase() or something? > > Now if the filename is empty that field doesn't appear, ok?
Correct. I think that the increment of 'i' should differ in the two cases though. The snippet below works perfectly. Many thanks for your help. def convert_external(lines): external_rexp = re.compile(r'\\begin_inset External ([^,]*),"([^"]*)",') top = "\\begin_inset External" i = 0 while 1: i = find_token(lines, top, i) if i == -1: break look = external_rexp.search(lines[i]) args = ['',''] if look: args[0] = look.group(1) args[1] = look.group(2) #FIXME: if the previous search fails then warn template = "\ttemplate " + args[0] if args[1]: filename = "\tfilename " + args[1] lines[i:i+1] = [top, template, filename] i=i+2 else: lines[i:i+1] = [top, template] i = i + 1 -- Angus