AttributeError
Ltc Hotspot
ltc.hotspot at gmail.com
Wed Aug 12 14:35:03 EDT 2015
Emile
How do I define time in the revised code ?
---------------------------------------------------------------------------
Traceback Message reads:
In [66]: %run assignment_10_2_v_07
NameError
Traceback (most recent call last)
C:\Users\vm\Desktop\apps\docs\Python\week_10\assignment_10_2_v_07.py in <module>
()
9 for line in handle:
10 if line.startswith("From "):
---> 11 for key, val in time.split()[5]:
12 for key, val in hours.split(':')[0]:
13 count[hours] = count.get(hours, 0) + 1 # counter
NameError: name 'time' is not defined
---------------------------------------------------------------------------
>>>
In [67]: print time
0
---------------------------------------------------------------------------
Revised Code reads:
handle = """From stephen.marquard at uct.ac.za Sat Jan 5 09:14:16 2008
>From louis at media.berkeley.edu Fri Jan 4 18:10:48 2008
""".split("\n")
# Snippet file data: mbox-short.txt
count = dict()
#fname = raw_input("Enter file name: ")# insert snippet file
#handle = open (fname, 'r')# insert snippet file
for line in handle:
if line.startswith("From "):
for key, val in time.split()[5]:
for key, val in hours.split(':')[0]:
count[hours] = count.get(hours, 0) + 1 # counter
lst = [(val,key) for key,val in count.items()]
lst.sort(reverse=True)
for key, val in lst[:12] :
print key, val
---------------------------------------------------------------------------
Regards,
Hal
More information about the Python-list
mailing list