AttributeError

Ltc Hotspot ltc.hotspot at gmail.com
Wed Aug 12 18:29:50 CEST 2015


Denis,


Using the attached file of a  diagram as a frame, why is there an
attribute message?



---------------------------------------------------------------------------------------------------------
Here is the attribute message:
AttributeError
Traceback (most recent call last)
C:\Users\vm\Desktop\apps\docs\Python\week_10\assignment_10_2_v_06.py in <module>
()
     11         time = line.split() # Sort time
     12
---> 13         hours = list.split(":")[5] # Sort hours
     14         line = line.rstrip()
     15         count[hours] = count.get(hours, 0) + 1

AttributeError: type object 'list' has no attribute 'split'

In [45]:

---------------------------------------------------------------------------------------------------------
Here is the revised code:
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: ")# Add Snippet file
#handle = open (fname, 'r')# Add Snippet file
for line in handle:
    if line.startswith("From "):
        time = line.split() # Sort time

        hours = time.split(":")[5] # Sort hours
        line = line.rstrip()

        count[hours] = count.get(hours, 0) + 1 # counter

lst = [(val,key) for key,val in count.items()]

print key, val



URL link, http://tinyurl.com/oyd4ugp


Regards,
Hal


More information about the Python-list mailing list