Hello ,
I created a small program to cut line from log file
but I feel I can write it better
can someone help with make the code better\smallest\ prettier?
**** also I have notice that if the file is bigger then 4GB - I get memory error
is there any way to overcome this problem ?
Thanks ,
I created a small program to cut line from log file
import sys OutputFile = open('C:\\Users\\David\\Desktop\\OutPutLog.txt', "w+") file1 = open('C:\\Users\\David\\Desktop\\Log.txt', 'r') Lines = file1.readlines() file1.close() StartDate = input('Enter Start Date\n') EndDate = input('Enter End Date\n') count = 0 StartLine = 0 EndLine = 0 # Strips the newline character for line in Lines: count += 1 if StartDate in line and StartLine == 0: print("Start Line {}: {}".format(count, line.strip())) StartLine = count if EndDate in line and EndLine == 0: print("End Line{}: {}".format(count, line.strip())) EndLine = count count = 0 print('start line is %d , end line is %d' % (StartLine, EndLine)) print('total number of line is %d' % (EndLine-StartLine)) for line in Lines: count += 1 if StartLine <= count <= EndLine: OutputFile.write(line.strip() + "\r\n")it's working
but I feel I can write it better
can someone help with make the code better\smallest\ prettier?
**** also I have notice that if the file is bigger then 4GB - I get memory error
is there any way to overcome this problem ?
Thanks ,