def FixIt(infile,outfile): # reads infile, and copies all chars except non-text and '\r' to outfile try: f=open(infile,'rb') instring=f.read() f.close() except: print ('Cannot read: '+infile) return outstring='' nremoved=0 for c in instring: if c==ord('\n') or c==ord('\t') or 32<=c<=127: outstring+=chr(c) else: nremoved+=1 try: f=open(outfile,'w',newline='\n') f.write(outstring) f.close() print ('Wrote %s. Removed %d chars.' % (outfile,nremoved)) except: print ('Could not write '+outfile) return