I am using Python 2.5 and trying to make a variable called total and add three files to it. Then I compress total and convert it to hex and split it into a list of strings with a maximum length of 4096 characters.
I currently have a list of files, and I am concatenating it all this way.
filelist = ['debug.log', 'error.log', 'reclog.log']; total = '' for files in filelist: f = open(files, 'r'); total = total + f.read(); f.close(); compressedtotal = zlib.compress(total); hextotal = compressedtotal.encode('hex');
Here I feel that I am doing it effectively. But then I try to split hextotal into a list of strings called msglist. But the maximum length of each line in msglist should be no more than 4096 characters.
if len(hextotal)%4096 >0 : checker = 1; else: checker = 0; nmsgs = int(math.ceil(len(hextotal)/4096)); nn = str(nmsgs); msglist = []; for msgs in range(1,nmsgs+1): if msgs == nmsgs and checker == 1: msglist.append(hextotal[4096*(msgs-1):]); else: msglist.append(hextotal[4096*(msgs-1):4096*(msgs)]);
I need a simpler way because it is not "pythonic", but im completely new to python. Extremely much.
source share