> -----Original Message----- > From: Python-list [mailto:python-list- > bounces+crk=godblessthe...@python.org] On Behalf Of Ltc Hotspot > Sent: Wednesday, August 12, 2015 9:57 AM > To: MRAB <pyt...@mrabarnett.plus.com> > Cc: python-list@python.org > Subject: Re: AttributeError > > MRAB, > > I ran the code, and the output: > > > Raw data code: > handle = """From stephen.marqu...@uct.ac.za Sat Jan 5 09:14:16 2008 From > lo...@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'
>From my naïve view what you wanted was not list.split but line.split. Isn't list a keyword or function? Crk > > In [46]: > > Regards, > Hal > > On Wed, Aug 12, 2015 at 9:45 AM, MRAB <pyt...@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.marqu...@uct.ac.za Sat Jan 5 09:14:16 2008 > >>> > >>> From lo...@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 > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list