python - read multiple file and compare with the fixed files -


i have 50 files in directory suppose compare 1 file, e.g., original.txt. have following code. works when give file name one-by-one, manually. want automate used 'glob.blog'

folder = "files/" path = '*.rbd'  path = folder + path files=sorted(glob.glob(path)) 

here complete code:

import glob itertools import islice import linecache  num_lines_nonbram =  1891427  bits_perline = 32  total_bit_flips =  0  num_bit_diff_flip_zero = 0 num_bit_diff_flip_ones = 0 folder = "files/"  path = '*.rbd'  path = folder + path files=sorted(glob.glob(path))  original=open('files/mull-original-readback.rbd','r')   #source1 = open(file1, "r")    filename in files:    del_lines = 101   open(filename,'r') f:    i=1   while <= del_lines:    line1 = f.readline()     lineoriginal=original.readline()     i+=1    i=0       num_bit_diff_flip_zero = 0   num_bit_diff_flip_ones = 0   num_lines_diff =0    i=0   j=0   k=0   a_write2 = ""   while < (num_lines_nonbram-del_lines):         line1 = f.readline()          lineoriginal = original.readline()             while k < bits_perline:                 if ((lineoriginal[k] == line1[k])):                      a_write2 += " "                 else:                      if (lineoriginal[k]=="0"):                       #if ((line1[k]=="0" , line1[k]=="1")):                        num_bit_diff_flip_zero += 1                      if (lineoriginal[k]=="1"):                       #if ((line1[k]=="0" , line1[k]=="1")):                        num_bit_diff_flip_ones += 1                       #if ((line1[k]==1 , line1[k]==0)):                       #a_write_file2 = str(i+1) + " " + str(31-k) + "\n" + a_write_file2                       #a_write2 += "^"                       #num_bit_diff_flip_one += 1                       # else:                     #    a_write2 += " "                   k+=1                   total_bit_flips=num_bit_diff_flip_zero+num_bit_diff_flip_ones         i+=1          k=0 = 0 print files print "number of bits flip zero= %d" %num_bit_diff_flip_zero +"\n" +"number of bits flip one= %d" %num_bit_diff_flip_ones +"\n" "total bit flips = %d " %total_bit_flips   f.close() original.close() 

i got error:

traceback (most recent call last):   file "random-ones-zeros.py", line 65, in <module>     if ((lineoriginal[k] == line1[k])): indexerror: string index out of range 

i guess there issue reading file automatically, instead giving name manually. but, didn't able find solution.

for string index out of range because value k iterated once more intended value of variable exceeds scope of program. should able fixed using substituting

if ((lineoriginal[k-1] == line1[k-1])):

hope helps, can't access python right can't test out :-)


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -