AttributeError
Ltc Hotspot
ltc.hotspot at gmail.com
Wed Aug 12 12:15:24 EDT 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
On Wed, Aug 12, 2015 at 8:50 AM, Denis McMahon <denismfmcmahon at gmail.com> wrote:
> On Tue, 11 Aug 2015 22:03:05 -0700, Ltc Hotspot wrote:
>
>> Question: What sorted function should I write to produce the desired
>> output, below:
>
> Me, I'd start by declaring a dictionary to hold the data:
>
> counts = { "{:02d}".format(h):0 for h in range(24) }
>
> Then I'd parse the strings in the log file(s), incrementing counts[x]
> where x is the hour field of the timestamp.
>
> Then I'd create a list of tuples:
>
> ncounts = [(k,v) for k,v in counts.items()]
>
> sort it by the hour field:
>
> ncounts.sort(key = lambda x: x[0])
>
> and print it:
>
> for x in ncounts:
> print x[0], x1
>
> --
> Denis McMahon, denismfmcmahon at gmail.com
> --
> https://mail.python.org/mailman/listinfo/python-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: diagram_1.pdf
Type: application/pdf
Size: 1215006 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20150812/2b1a5417/attachment.pdf>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: diagram_2.pdf
Type: application/pdf
Size: 1102835 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20150812/2b1a5417/attachment-0001.pdf>
More information about the Python-list
mailing list