-3

I need read a log with this structure:

w00041c0da70021002206900691

i use this code for read but does not work

results = [line[10:13] for line in f.readlines() if line[10:13] == "7002"]

I need the number of lines that have the number 7002 in position 10 to 13

Vim
  • 578
  • 5
  • 16
Dobled
  • 5
  • 1

2 Answers2

0
with open('file.log','r') as logFile:
    output = logFile.read()
    #Iterate over lines and slice each row's data
    #logData[10:14] == '7002'
static const
  • 953
  • 4
  • 16
0
count = 0
for line in f.readlines():
    if line[10:13] == "7002":
        count += 1
print("Count :",count)

if you want to do the count in list comprehension , have a look at Maintain count in python list comprehension

Vim
  • 578
  • 5
  • 16
  • I tested this code and does not work for "7002" but if i use only one number example "7" work fine. it's very strange – Dobled Jun 21 '19 at 14:58