Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #95263 > unrolled thread
| Started by | Ltc Hotspot <ltc.hotspot@gmail.com> |
|---|---|
| First post | 2015-08-11 17:01 -0700 |
| Last post | 2015-08-12 23:16 +0100 |
| Articles | 20 on this page of 46 — 10 participants |
Back to article view | Back to comp.lang.python
AttributeError Ltc Hotspot <ltc.hotspot@gmail.com> - 2015-08-11 17:01 -0700
Re: AttributeError leo kirotawa <kirotawa@gmail.com> - 2015-08-11 21:16 -0300
Re: AttributeError MRAB <python@mrabarnett.plus.com> - 2015-08-12 01:26 +0100
Re: AttributeError Chris Angelico <rosuav@gmail.com> - 2015-08-12 10:49 +1000
Re: AttributeError MRAB <python@mrabarnett.plus.com> - 2015-08-12 01:58 +0100
Re: AttributeError Ltc Hotspot <ltc.hotspot@gmail.com> - 2015-08-11 22:03 -0700
Re: AttributeError MRAB <python@mrabarnett.plus.com> - 2015-08-12 16:12 +0100
Re: AttributeError Denis McMahon <denismfmcmahon@gmail.com> - 2015-08-12 15:50 +0000
Re: AttributeError Ltc Hotspot <ltc.hotspot@gmail.com> - 2015-08-12 09:29 -0700
Re: AttributeError MRAB <python@mrabarnett.plus.com> - 2015-08-12 17:45 +0100
Re: AttributeError Ltc Hotspot <ltc.hotspot@gmail.com> - 2015-08-12 09:57 -0700
Re: AttributeError MRAB <python@mrabarnett.plus.com> - 2015-08-12 18:24 +0100
RE: AttributeError "Clayton Kirkwood" <crk@godblessthe.us> - 2015-08-12 10:31 -0700
Re: AttributeError Emile van Sebille <emile@fenx.com> - 2015-08-12 10:37 -0700
Re: AttributeError Ltc Hotspot <ltc.hotspot@gmail.com> - 2015-08-12 11:35 -0700
Re: AttributeError MRAB <python@mrabarnett.plus.com> - 2015-08-12 19:59 +0100
Re: AttributeError Ltc Hotspot <ltc.hotspot@gmail.com> - 2015-08-12 12:05 -0700
Re: AttributeError Denis McMahon <denismfmcmahon@gmail.com> - 2015-08-12 20:38 +0000
RE: AttributeError "Clayton Kirkwood" <crk@godblessthe.us> - 2015-08-12 14:15 -0700
Re: AttributeError Emile van Sebille <emile@fenx.com> - 2015-08-12 14:32 -0700
Re: AttributeError Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-08-12 22:45 +0100
Re: AttributeError Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-08-12 22:51 +0100
Re: AttributeError Ltc Hotspot <ltc.hotspot@gmail.com> - 2015-08-12 14:04 -0700
Re: AttributeError Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-08-13 10:37 +0100
Re: AttributeError Ben Finney <ben+python@benfinney.id.au> - 2015-08-13 21:08 +1000
Re: AttributeError MRAB <python@mrabarnett.plus.com> - 2015-08-12 21:04 +0100
Re: AttributeError Denis McMahon <denismfmcmahon@gmail.com> - 2015-08-12 21:16 +0000
Re: AttributeError MRAB <python@mrabarnett.plus.com> - 2015-08-12 23:35 +0100
Re: AttributeError Ltc Hotspot <ltc.hotspot@gmail.com> - 2015-08-12 16:05 -0700
Re: AttributeError Emile van Sebille <emile@fenx.com> - 2015-08-12 16:15 -0700
Re: AttributeError MRAB <python@mrabarnett.plus.com> - 2015-08-13 00:16 +0100
Re: AttributeError Ltc Hotspot <ltc.hotspot@gmail.com> - 2015-08-12 16:46 -0700
Re: AttributeError Denis McMahon <denismfmcmahon@gmail.com> - 2015-08-13 09:15 +0000
Re: AttributeError Ltc Hotspot <ltc.hotspot@gmail.com> - 2015-08-13 02:41 -0700
Re: AttributeError Denis McMahon <denismfmcmahon@gmail.com> - 2015-08-13 11:06 +0000
Re: AttributeError MRAB <python@mrabarnett.plus.com> - 2015-08-13 00:56 +0100
Re: AttributeError Denis McMahon <denismfmcmahon@gmail.com> - 2015-08-12 20:28 +0000
Re: AttributeError Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-08-12 21:58 +0100
Re: AttributeError Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-08-12 03:46 +0100
Re: AttributeError Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-08-12 04:32 +0100
Re: AttributeError Chris Angelico <rosuav@gmail.com> - 2015-08-12 13:49 +1000
Re: AttributeError Denis McMahon <denismfmcmahon@gmail.com> - 2015-08-12 11:36 +0000
Re: AttributeError MRAB <python@mrabarnett.plus.com> - 2015-08-12 16:09 +0100
Re: AttributeError Gene Heskett <gheskett@wdtv.com> - 2015-08-12 17:25 -0400
Re: AttributeError Ltc Hotspot <ltc.hotspot@gmail.com> - 2015-08-12 15:02 -0700
Re: AttributeError Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-08-12 23:16 +0100
Page 1 of 3 [1] 2 3 Next page →
| From | Ltc Hotspot <ltc.hotspot@gmail.com> |
|---|---|
| Date | 2015-08-11 17:01 -0700 |
| Subject | AttributeError |
| Message-ID | <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> |
Hi Everyone,
What is the list equivalent to line 12: ncount.sort(reverse=True)
count = dict()
fname = raw_input("Enter file name: ")#
handle = open (fname, 'r')#
for line in handle:
if line.startswith("From "):
address = line.split()[5]
line = line.rstrip()
count[address] = count.get(address, 0) + 1
for key,val in count.items():
ncount = (key,val)
ncount.sort(reverse=True)
print key,val
Error message, reads: AttributeError, line 12, below : 'tuple' object has no attribute 'sort'
Raw data code, available at http://tinyurl.com/ob89r9p
Embedded data code, available at http://tinyurl.com/qhm4ppq
Visualization URL link, available at http://tinyurl.com/ozzmffy
Regards,
Hal
[toc] | [next] | [standalone]
| From | leo kirotawa <kirotawa@gmail.com> |
|---|---|
| Date | 2015-08-11 21:16 -0300 |
| Message-ID | <mailman.89.1439338622.3627.python-list@python.org> |
| In reply to | #95263 |
assign using () creates tuple not a list. Tuples have not .sort() method.
correct would be:
ncount = [key,val]
On Tue, Aug 11, 2015 at 9:01 PM, Ltc Hotspot <ltc.hotspot@gmail.com> wrote:
> Hi Everyone,
>
>
> What is the list equivalent to line 12: ncount.sort(reverse=True)
>
>
> count = dict()
> fname = raw_input("Enter file name: ")#
> handle = open (fname, 'r')#
> for line in handle:
> if line.startswith("From "):
> address = line.split()[5]
> line = line.rstrip()
> count[address] = count.get(address, 0) + 1
>
> for key,val in count.items():
> ncount = (key,val)
> ncount.sort(reverse=True)
> print key,val
>
>
> Error message, reads: AttributeError, line 12, below : 'tuple' object has no attribute 'sort'
>
> Raw data code, available at http://tinyurl.com/ob89r9p
> Embedded data code, available at http://tinyurl.com/qhm4ppq
> Visualization URL link, available at http://tinyurl.com/ozzmffy
>
>
> Regards,
> Hal
> --
> https://mail.python.org/mailman/listinfo/python-list
--
----------------------------------------------
Leônidas S. Barbosa (Kirotawa)
blog: corecode.wordpress.com
[toc] | [prev] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2015-08-12 01:26 +0100 |
| Message-ID | <mailman.90.1439339198.3627.python-list@python.org> |
| In reply to | #95263 |
On 2015-08-12 01:01, Ltc Hotspot wrote:
> Hi Everyone,
>
>
> What is the list equivalent to line 12: ncount.sort(reverse=True)
>
>
> count = dict()
> fname = raw_input("Enter file name: ")#
> handle = open (fname, 'r')#
> for line in handle:
> if line.startswith("From "):
> address = line.split()[5]
> line = line.rstrip()
> count[address] = count.get(address, 0) + 1
>
> for key,val in count.items():
> ncount = (key,val)
> ncount.sort(reverse=True)
> print key,val
>
>
> Error message, reads: AttributeError, line 12, below : 'tuple' object has no attribute 'sort'
>
> Raw data code, available at http://tinyurl.com/ob89r9p
> Embedded data code, available at http://tinyurl.com/qhm4ppq
> Visualization URL link, available at http://tinyurl.com/ozzmffy
>
What are you trying to do? Why are you trying to sort a key/value pair
in reverse order?
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2015-08-12 10:49 +1000 |
| Message-ID | <mailman.92.1439340553.3627.python-list@python.org> |
| In reply to | #95263 |
On Wed, Aug 12, 2015 at 10:43 AM, Ltc Hotspot <ltc.hotspot@gmail.com> wrote:
> Python can pull the hour from the 'From ' line by finding the time and then
> splitting the string a second time using a colon, i.e., From
> stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008
>
> Finally, accumulated the counts for each hour, print out the counts, sorted
> by hour as shown below:
In that case, you want to sort the entire collection, not a single
key-value pair.
It seems to me you can do this fairly efficiently with collections.Counter.
import collections
with open(raw_input("Enter file name: ")) as f:
counts = collections.Counter(line.split()[5].rstrip() for line in
f if line.startswith("From "))
counts = counts.items()
counts.sort()
for hour, count in counts:
print hour, count
The most important part is getting items() and then sorting the whole thing.
ChrisA
[toc] | [prev] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2015-08-12 01:58 +0100 |
| Message-ID | <mailman.94.1439341104.3627.python-list@python.org> |
| In reply to | #95263 |
On 2015-08-12 01:43, Ltc Hotspot wrote:
> The Assignment:
>
>
>
> I'm trying to write Python code to read through a data file and figure
> out the distribution by hour of the dat for each message in the data file.
>
> Python can pull the hour from the 'From ' line by finding the time and
> then splitting the string a second time using a colon, i.e., From
> stephen.marquard@uct.ac.za <mailto:stephen.marquard@uct.ac.za> Sat Jan
> 5 09:14:16 2008
>
> Finally, accumulated the counts for each hour, print out the counts,
> sorted by hour as shown below:
>
> name = raw_input("Enter file:")
> if len(name) < 1 : name = "mbox-short.txt"
> handle = open(name)
>
>
> Desired Output:
>
>
> 04 3
> 06 1
> 07 1
> 09 2
> 10 3
> 11 6
> 14 1
> 15 2
> 16 4
> 17 2
> 18 1
> 19 1
>
Well, line.split()[5] isn't the address, it's the time, e.g. "09:14:16".
You need to do just a little more work to extract the hour.
I don't know what you think you'll achieve by sorting key/value pairs in
reverse order. What you should be doing is sorting the keys (hours),
although sorting the pairs of keys and values (i.e., the items) would
have the same effect. Have a look at the 'sorted' function.
>
>
> Raw data code, available at http://tinyurl.com/ob89r9p
> Embedded data code, available at http://tinyurl.com/qhm4ppq
> Visualization URL link, available at http://tinyurl.com/ozzmffy
>
> Regards,
> Hal
>
> On Tue, Aug 11, 2015 at 5:26 PM, MRAB <python@mrabarnett.plus.com
> <mailto:python@mrabarnett.plus.com>> wrote:
>
> On 2015-08-12 01:01, Ltc Hotspot wrote:
>
> Hi Everyone,
>
>
> What is the list equivalent to line 12: ncount.sort(reverse=True)
>
>
> count = dict()
> fname = raw_input("Enter file name: ")#
> handle = open (fname, 'r')#
> for line in handle:
> if line.startswith("From "):
> address = line.split()[5]
> line = line.rstrip()
> count[address] = count.get(address, 0) + 1
>
> for key,val in count.items():
> ncount = (key,val)
> ncount.sort(reverse=True)
> print key,val
>
>
> Error message, reads: AttributeError, line 12, below : 'tuple'
> object has no attribute 'sort'
>
> Raw data code, available at http://tinyurl.com/ob89r9p
> Embedded data code, available at http://tinyurl.com/qhm4ppq
> Visualization URL link, available at http://tinyurl.com/ozzmffy
>
> What are you trying to do? Why are you trying to sort a key/value
> pair in reverse order?
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
>
[toc] | [prev] | [next] | [standalone]
| From | Ltc Hotspot <ltc.hotspot@gmail.com> |
|---|---|
| Date | 2015-08-11 22:03 -0700 |
| Message-ID | <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> |
| In reply to | #95268 |
Message heard loud and clear:
There are no error messages, the output is the issue.
Question: What sorted function should I write to produce the desired
output, below:
Desired output:
04 3
06 1
07 1
09 2
10 3
11 6
14 1
15 2
16 4
17 2
18 1
19 1
Latest revised code:
count = dict()
fname = raw_input("Enter file name: ")#
handle = open (fname, 'r')#
for line in handle:
if line.startswith("From "):
address = line.split()[5]
line = line.rstrip()
count[address] = count.get(address, 0) + 1
lst = list()
for key,val in count.items():
lst.append( (val, key) )
lst.sort(reverse=True)
for val, key in lst[:12]:
print key,val
Output code:
In [3]: %run assignment_10_2_v_01
Enter file name: mbox-short.txt
16:23:48 1
16:23:48 1
11:11:52 1
17:07:00 1
16:23:48 1
11:11:52 1
17:07:00 1
16:23:48 1
11:11:52 1
04:07:34 1
17:07:00 1
16:23:48 1
11:11:52 1
07:02:32 1
04:07:34 1
17:07:00 1
16:23:48 1
11:12:37 1
11:11:52 1
07:02:32 1
04:07:34 1
17:07:00 1
16:23:48 1
14:50:18 1
11:12:37 1
11:11:52 1
07:02:32 1
04:07:34 1
17:07:00 1
16:23:48 1
14:50:18 1
11:35:08 1
11:12:37 1
11:11:52 1
07:02:32 1
04:07:34 1
17:07:00 1
16:23:48 1
14:50:18 1
11:37:30 1
11:35:08 1
11:12:37 1
11:11:52 1
07:02:32 1
04:07:34 1
18:10:48 1
17:07:00 1
16:23:48 1
14:50:18 1
11:37:30 1
11:35:08 1
11:12:37 1
11:11:52 1
07:02:32 1
04:07:34 1
18:10:48 1
17:07:00 1
16:23:48 1
14:50:18 1
11:37:30 1
11:35:08 1
11:12:37 1
11:11:52 1
11:10:22 1
07:02:32 1
04:07:34 1
19:51:21 1
18:10:48 1
17:07:00 1
16:23:48 1
14:50:18 1
11:37:30 1
11:35:08 1
11:12:37 1
11:11:52 1
11:10:22 1
07:02:32 1
04:07:34 1
19:51:21 1
18:10:48 1
17:07:00 1
16:23:48 1
15:46:24 1
14:50:18 1
11:37:30 1
11:35:08 1
11:12:37 1
11:11:52 1
11:10:22 1
07:02:32 1
19:51:21 1
18:10:48 1
17:07:00 1
16:23:48 1
16:10:39 1
15:46:24 1
14:50:18 1
11:37:30 1
11:35:08 1
11:12:37 1
11:11:52 1
11:10:22 1
19:51:21 1
18:10:48 1
17:07:00 1
16:23:48 1
16:10:39 1
15:46:24 1
14:50:18 1
11:37:30 1
11:35:08 1
11:12:37 1
11:11:52 1
11:10:22 1
19:51:21 1
18:10:48 1
17:07:00 1
16:34:40 1
16:23:48 1
16:10:39 1
15:46:24 1
14:50:18 1
11:37:30 1
11:35:08 1
11:12:37 1
11:11:52 1
19:51:21 1
18:10:48 1
17:07:00 1
16:34:40 1
16:23:48 1
16:10:39 1
15:46:24 1
14:50:18 1
11:37:30 1
11:35:08 1
11:12:37 1
11:11:52 1
19:51:21 1
18:10:48 1
17:07:00 1
16:34:40 1
16:23:48 1
16:10:39 1
15:46:24 1
14:50:18 1
11:37:30 1
11:35:08 1
11:12:37 1
11:11:52 1
19:51:21 1
18:10:48 1
17:07:00 1
16:34:40 1
16:29:07 1
16:23:48 1
16:10:39 1
15:46:24 1
14:50:18 1
11:37:30 1
11:35:08 1
11:12:37 1
19:51:21 1
18:10:48 1
17:07:00 1
16:34:40 1
16:29:07 1
16:23:48 1
16:10:39 1
15:46:24 1
15:03:18 1
14:50:18 1
11:37:30 1
11:35:08 1
19:51:21 1
18:10:48 1
17:07:00 1
16:34:40 1
16:29:07 1
16:23:48 1
16:10:39 1
15:46:24 1
15:03:18 1
14:50:18 1
11:37:30 1
11:35:08 1
19:51:21 1
18:10:48 1
17:07:00 1
16:34:40 1
16:29:07 1
16:23:48 1
16:10:39 1
15:46:24 1
15:03:18 1
14:50:18 1
11:37:30 1
11:35:08 1
19:51:21 1
18:10:48 1
17:07:00 1
16:34:40 1
16:29:07 1
16:23:48 1
16:10:39 1
15:46:24 1
15:03:18 1
14:50:18 1
11:37:30 1
11:35:08 1
19:51:21 1
18:10:48 1
17:18:23 1
17:07:00 1
16:34:40 1
16:29:07 1
16:23:48 1
16:10:39 1
15:46:24 1
15:03:18 1
14:50:18 1
11:37:30 1
19:51:21 1
18:10:48 1
17:18:23 1
17:07:00 1
16:34:40 1
16:29:07 1
16:23:48 1
16:10:39 1
15:46:24 1
15:03:18 1
14:50:18 1
11:37:30 1
19:51:21 1
18:10:48 1
17:18:23 1
17:07:00 1
16:34:40 1
16:29:07 1
16:23:48 1
16:10:39 1
15:46:24 1
15:03:18 1
14:50:18 1
11:37:30 1
19:51:21 1
18:10:48 1
17:18:23 1
17:07:00 1
16:34:40 1
16:29:07 1
16:23:48 1
16:10:39 1
15:46:24 1
15:03:18 1
14:50:18 1
11:37:30 1
In [4]:
Regards,
Hal
> >
> >
> > Error message, reads: AttributeError, line 12, below : 'tuple'
> > object has no attribute 'sort'
> >
> > Raw data code, available at http://tinyurl.com/ob89r9p
> > Embedded data code, available at http://tinyurl.com/qhm4ppq
> > Visualization URL link, available at http://tinyurl.com/ozzmffy
> >
> > What are you trying to do? Why are you trying to sort a key/value
> > pair in reverse order?
> >
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >
> >
[toc] | [prev] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2015-08-12 16:12 +0100 |
| Message-ID | <mailman.109.1439392369.3627.python-list@python.org> |
| In reply to | #95272 |
On 2015-08-12 06:03, Ltc Hotspot wrote:
> Message heard loud and clear:
>
> There are no error messages, the output is the issue.
>
> Question: What sorted function should I write to produce the desired
> output, below:
>
Instead of iterating over "count.items()", iterate over
"sorted(count.items())".
> Desired output:
>
> 04 3
> 06 1
> 07 1
> 09 2
> 10 3
> 11 6
> 14 1
> 15 2
> 16 4
> 17 2
> 18 1
> 19 1
>
> Latest revised code:
>
> count = dict()
> fname = raw_input("Enter file name: ")#
> handle = open (fname, 'r')#
> for line in handle:
> if line.startswith("From "):
> address = line.split()[5]
> line = line.rstrip()
> count[address] = count.get(address, 0) + 1
>
> lst = list()
> for key,val in count.items():
> lst.append( (val, key) )
> lst.sort(reverse=True)
> for val, key in lst[:12]:
> print key,val
>
[snip]
I don't know why you have a nested 'for' loop; just iterate over the
sorted items and print them. Simple.
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2015-08-12 15:50 +0000 |
| Message-ID | <mqfq0t$8np$2@dont-email.me> |
| In reply to | #95272 |
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@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | Ltc Hotspot <ltc.hotspot@gmail.com> |
|---|---|
| Date | 2015-08-12 09:29 -0700 |
| Message-ID | <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> |
| In reply to | #95286 |
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@uct.ac.za Sat Jan 5 09:14:16 2008
From louis@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
[toc] | [prev] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2015-08-12 17:45 +0100 |
| Message-ID | <mailman.124.1439397928.3627.python-list@python.org> |
| In reply to | #95293 |
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@uct.ac.za Sat Jan 5 09:14:16 2008
>>From louis@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
>
[toc] | [prev] | [next] | [standalone]
| From | Ltc Hotspot <ltc.hotspot@gmail.com> |
|---|---|
| Date | 2015-08-12 09:57 -0700 |
| Message-ID | <mailman.126.1439398622.3627.python-list@python.org> |
| In reply to | #95293 |
MRAB,
I ran the code, and the output:
Raw data code:
handle = """From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008
>From louis@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@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@uct.ac.za Sat Jan 5 09:14:16 2008
>>>
>>> From louis@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
[toc] | [prev] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2015-08-12 18:24 +0100 |
| Message-ID | <mailman.128.1439400287.3627.python-list@python.org> |
| In reply to | #95293 |
On 2015-08-12 17:57, Ltc Hotspot wrote:
> MRAB,
>
> I ran the code, and the output:
>
>
> Raw data code:
> handle = """From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008
> >From louis@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]:
Read the indicated line _carefully_.
What is it _actually_ trying to split?
[toc] | [prev] | [next] | [standalone]
| From | "Clayton Kirkwood" <crk@godblessthe.us> |
|---|---|
| Date | 2015-08-12 10:31 -0700 |
| Message-ID | <mailman.129.1439400787.3627.python-list@python.org> |
| In reply to | #95293 |
> -----Original Message-----
> From: Python-list [mailto:python-list-
> bounces+crk=godblessthe.us@python.org] On Behalf Of Ltc Hotspot
> Sent: Wednesday, August 12, 2015 9:57 AM
> To: MRAB <python@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.marquard@uct.ac.za Sat Jan 5 09:14:16 2008 From
> louis@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 <python@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@uct.ac.za Sat Jan 5 09:14:16 2008
> >>>
> >>> From louis@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
[toc] | [prev] | [next] | [standalone]
| From | Emile van Sebille <emile@fenx.com> |
|---|---|
| Date | 2015-08-12 10:37 -0700 |
| Message-ID | <mailman.131.1439401060.3627.python-list@python.org> |
| In reply to | #95293 |
On 8/12/2015 10:24 AM, MRAB wrote: > What is it _actually_ trying to split? Aah, reading. Such an underused skill. Emile
[toc] | [prev] | [next] | [standalone]
| From | Ltc Hotspot <ltc.hotspot@gmail.com> |
|---|---|
| Date | 2015-08-12 11:35 -0700 |
| Message-ID | <5a09701f-06d3-42dd-aa96-59920de76044@googlegroups.com> |
| In reply to | #95304 |
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@uct.ac.za Sat Jan 5 09:14:16 2008
From louis@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
[toc] | [prev] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2015-08-12 19:59 +0100 |
| Message-ID | <mailman.133.1439405954.3627.python-list@python.org> |
| In reply to | #95305 |
On 2015-08-12 19:35, Ltc Hotspot wrote:
> Emile
>
> How do I define time in the revised code ?
>
>
Have a look at assignment_10_2_v_06.py.
>
> ---------------------------------------------------------------------------
> 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@uct.ac.za Sat Jan 5 09:14:16 2008
>>From louis@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
>
I'm baffled as to why you now have a nested 'for' loop 3 levels deep!
[toc] | [prev] | [next] | [standalone]
| From | Ltc Hotspot <ltc.hotspot@gmail.com> |
|---|---|
| Date | 2015-08-12 12:05 -0700 |
| Message-ID | <mailman.134.1439406339.3627.python-list@python.org> |
| In reply to | #95305 |
>Have a look at assignment_10_2_v_06.py.
What should I look at assignment_10_2_v_06.py.:
handle = """From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008
>From louis@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 = line.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
On Wed, Aug 12, 2015 at 11:59 AM, MRAB <python@mrabarnett.plus.com> wrote:
> On 2015-08-12 19:35, Ltc Hotspot wrote:
>>
>> Emile
>>
>> How do I define time in the revised code ?
>>
>>
> Have a look at assignment_10_2_v_06.py.
>
>>
>>
>> ---------------------------------------------------------------------------
>> 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@uct.ac.za Sat Jan 5 09:14:16 2008
>>>
>>> From louis@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
>>
> I'm baffled as to why you now have a nested 'for' loop 3 levels deep!
>
> --
> https://mail.python.org/mailman/listinfo/python-list
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2015-08-12 20:38 +0000 |
| Message-ID | <mqgasa$8np$4@dont-email.me> |
| In reply to | #95308 |
On Wed, 12 Aug 2015 12:05:37 -0700, Ltc Hotspot wrote: >>Have a look at assignment_10_2_v_06.py. > What should I look at assignment_10_2_v_06.py.: You shouldn't. You should instead approach your tutor and tell him you are too stupid to learn computer programming[1], and can you please transfer to floor-scrubbing 101. [1] You have repeatedly ignored advice and instructions that you have been given. This is de-facto proof that you are not capable of learning to program computers. -- Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | "Clayton Kirkwood" <crk@godblessthe.us> |
|---|---|
| Date | 2015-08-12 14:15 -0700 |
| Message-ID | <mailman.138.1439414235.3627.python-list@python.org> |
| In reply to | #95311 |
I'm thinking we are being played by a Turing type machine. crk > -----Original Message----- > From: Python-list [mailto:python-list- > bounces+crk=godblessthe.us@python.org] On Behalf Of Denis McMahon > Sent: Wednesday, August 12, 2015 1:39 PM > To: python-list@python.org > Subject: Re: AttributeError > > On Wed, 12 Aug 2015 12:05:37 -0700, Ltc Hotspot wrote: > > >>Have a look at assignment_10_2_v_06.py. > > > What should I look at assignment_10_2_v_06.py.: > > You shouldn't. You should instead approach your tutor and tell him you are > too stupid to learn computer programming[1], and can you please transfer to > floor-scrubbing 101. > > [1] You have repeatedly ignored advice and instructions that you have been > given. This is de-facto proof that you are not capable of learning to program > computers. > > -- > Denis McMahon, denismfmcmahon@gmail.com > -- > https://mail.python.org/mailman/listinfo/python-list
[toc] | [prev] | [next] | [standalone]
| From | Emile van Sebille <emile@fenx.com> |
|---|---|
| Date | 2015-08-12 14:32 -0700 |
| Message-ID | <mailman.140.1439415169.3627.python-list@python.org> |
| In reply to | #95311 |
On 8/12/2015 1:38 PM, Denis McMahon wrote: > On Wed, 12 Aug 2015 12:05:37 -0700, Ltc Hotspot wrote: > >>> Have a look at assignment_10_2_v_06.py. > >> What should I look at assignment_10_2_v_06.py.: > > You shouldn't. You should instead approach your tutor and tell him you > are too stupid to learn computer programming[1], and can you please > transfer to floor-scrubbing 101. > > [1] You have repeatedly ignored advice and instructions that you have > been given. This is de-facto proof that you are not capable of learning > to program computers. Ooooh! I've heard stories people were released from *mart (or was that dell?) for comments like that. :) However-a-propos-ly y'rs, Emile @ltc -- read this -- then re-read all the responses you've been given. Repeat ad nauseam. Until you can understand and incorporate advice given you're wasting your time and ours asking.
[toc] | [prev] | [next] | [standalone]
Page 1 of 3 [1] 2 3 Next page →
Back to top | Article view | comp.lang.python
csiph-web