<snip> > > > As for splitting into functions, consider: > > #these two are capitalized because they're intended to be constant > TOKENS = "BE" > LINESTOSKIP = 43 > INFILEEXT = ".xpm" > OUTFILEEXT = ".txt" > > def dofiles(topdirectory): > for filename in os.listdr(topdirectory): > processfile(filename) > > def processfile(infilename): > base, ext =os.path.splitext(fileName) > if ext == INFILEEXT: > text = fetchonefiledata(infilename) > numcolumns = len(text[0]) > results = {} > for ch in TOKENS: > > results[ch] = [0] * numcolumns > for line in text: > line = line.strip() > > for col, ch in enumerate(line): > if ch in tokens: > results[ch][col] += 1 > I still have trouble understanding the results[ch][col] part.
Thanks ahead, > writeonefiledata(base+**OUTFILEEXT, results) > > def fetchonefiledata(inname): > infile = open(inname) > text = infile.readlines() > return text[LINESTOSKIP:] > > def writeonefiledata(outname): > outfile = open(outname, "w") > ...process the results as appropriate... > ....(since you didn't tell us how multiple tokens were to be displayed) > > if __name__ == "__main__": > dofiles(".") #or get the top directory from the sys.argv variable, > which is set from command line. > > > > -- > > DaveA > > -- Best Regards, lina
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor