Jan-30-2023, 09:00 AM
Here is what I tried, but it does not seem to work.
# Convert import codecs import re def FixXrefs(xref): global bookname global bookno lg.write("----- Entered function\n") instuff=xref otstuff="" n=len(bookname) for i in bookno: j=int(i)-1 pattern = bookname[j]+" " replaceWith = i+"." lg.write("|"+pattern+"|"+replaceWith+"|\n") otstuff=instuff.replace(pattern, replaceWith) instuff=otstuff.replace(":", ".") return instuff lg=open("log.txt", "w") bookname=[] bookno=[] #set up bookname/bookno table bn=codecs.open("Boeke.txt", "r", "utf-8") while True: l=bn.readline() l.strip('\n') if ("" == l): lg.write("End of bookname/no file reached\n") break #parse string words = l.split(",") bookno.append(words[0]) bookname.append(words[2]) bn.close() # Now read the file to reformat fn=codecs.open("Conv.txt", "r", "utf-8") while True: irec=fn.readline() pline="INREC\n"+irec lg.write(pline) if ("" == irec): lg.write ("End of Conv file reached\n") break; nxref = FixXrefs(irec) pline="NXREF\n"+nxref lg.write(pline) lg.close() fn.close()