AttributeError
Ltc Hotspot
ltc.hotspot at gmail.com
Wed Aug 12 12:57:00 EDT 2015
MRAB,
I ran the code, and the output:
Raw data 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 = list.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
-------------------------------------------------------------------------------------
Syntax message:
In [45]: %run assignment_10_2_v_06
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
AttributeError: type object 'list' has no attribute 'split'
In [46]:
Regards,
Hal
On Wed, Aug 12, 2015 at 9:45 AM, MRAB <python at mrabarnett.plus.com> wrote:
> On 2015-08-12 17:29, Ltc Hotspot wrote:
>>
>> Denis,
>>
>>
>> Using the attached file of a diagram as a frame, why is there an
>> attribute message?
>>
> The code in the error report doesn't match the "revised code".
>
>>
>>
>>
>> ---------------------------------------------------------------------------------------------------------
>> 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
>>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list