# python3 import os import fnmatch with open('report.txt','w',encoding='utf8') as report: for path,dirs,files in os.walk('d:/dev/boost_1_50_0/boost'): for file_ in fnmatch.filter(files,'*.hpp'): filename = os.path.normpath(os.path.join(path,file_)) with open(filename,'rb') as testfile: data = testfile.read() try: data.decode('ascii') except UnicodeDecodeError as e: line = data[:e.start].count(b'\n') data = data.decode('latin-1').split('\n') report.write('{}({}) : {}\n'.format(filename,line,data[line]))