I'm trying to write a code, which extracts timecodes from lines that start with "From". Example: "From [email protected] Sat Jan 5 09:14:16 2008" and then splits the timecode into hours and seconds.
fhand = open('mbox-short.txt')
for line in fhand :
line = line.rstrip()
if not line.startswith('From') : continue
words = line.split()
time = words[5:6]
hrs = time.split(':')
print(hrs[1])
print(hrs[2])
When I'm compiling my code - I'm getting the traceback (Attribute Error: 'list' object has no attribute 'split'). If I change my code to do the same for email:
fhand = open('mbox-short.txt')
for line in fhand :
line = line.rstrip()
if not line.startswith('From') : continue
words = line.split()
time = words[1]
hrs = time.split('@')
print(hrs[1])
everything is alright - the program works properly (splits emails into logins and domains). What's wrong with the first code?
words[5:6]returns a list even if there is only one thing in it