#!/usr/bin/python3

import os.path
import glob

TOKENS="BE"
LINESTOSKIP=0
INFILEEXT=".xpm"
OUTFILEEXT=".txt"


if __name__=="__main__":

    for fileName in glob.glob('*.xpm'):
        base, ext =os.path.splitext(fileName)
        text=open(fileName).readlines()
        text=text[LINESTOSKIP:]
        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
        summary=[]
        for a,b in zip(results['E'],results['B']):
            summary.append(a+b)
        print(summary)
        open(base+OUTFILEEXT,"w").write(str(summary))

I test it, it finally works. (I was not so sensitive about indentation also)

If you have time or interest, hope to help polish the code,
and warmly welcome to make above one a bit sophisticated. better not
easy-readable for me at first sight.

Thanks again,
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to