with open(logPath, "r") as f:
for line in (l.rstrip() for l in f):
match= format_pat.match(line)
if match:
access = match.groupdict()
request = access['request']
(action, URL, protocol) = request.split()
if URL in URLCounts:
URLCounts[URL] = URLCounts[URL] + 1
else:
URLCounts[URL] = 1
this is my code : URLCounts = {}
with open(logPath, "r") as f: for line in (l.rstrip() for l in f): match= format_pat.match(line) if match: access = match.groupdict() request = access['request'] (action, URL, protocol) = request.split() if URL in URLCounts: URLCounts[URL] = URLCounts[URL] + 1 else: URLCounts[URL] = 1
results = sorted(URLCounts, key=lambda i: int(URLCounts[i]), reverse=True)
for result in results[:20]: print(result + ": " + str(URLCounts[result]))
this is error :
ValueError Traceback (most recent call last)