Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #95320
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ltc.hotspot@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'mrab': 0.05; 'assignment': 0.07; 'data:': 0.07; 'f.close()': 0.07; 'filename': 0.07; 'val': 0.07; 'cc:addr:python-list': 0.09; 'bills.': 0.09; 'lst': 0.09; 'nameerror:': 0.09; 'snippet': 0.09; 'thread': 0.10; 'jan': 0.11; 'wed,': 0.15; 'wednesday': 0.15; '11:59': 0.16; 'curriculum.': 0.16; 'handle:': 0.16; 'last)': 0.16; 'learns': 0.16; 'line.split()': 0.16; 'nameerror': 0.16; 'otoh,': 0.16; 'perceived': 0.16; 'soap,': 0.16; 'venues.': 0.16; 'wrote:': 0.16; 'debugging': 0.18; 'nested': 0.18; '>>>': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'aug': 0.20; 'fix': 0.21; "aren't": 0.22; 'cheers,': 0.22; 'am,': 0.23; 'defined': 0.23; 'bit': 0.23; 'academic': 0.23; 'insert': 0.23; '(most': 0.24; 'header:In-Reply-To:1': 0.24; 'sort': 0.25; 'error': 0.27; 'define': 0.27; 'followed': 0.27; 'least': 0.27; 'message- id:@mail.gmail.com': 0.27; 'key,': 0.29; 'code:': 0.29; "i'm": 0.30; 'print': 0.30; 'url:mailman': 0.30; 'code': 0.30; 'putting': 0.30; 'error.': 0.31; 'fixed': 0.31; 'another': 0.32; 'problem': 0.33; 'url:python': 0.33; 'sat': 0.33; 'traceback': 0.33; 'open': 0.33; 'url:listinfo': 0.34; 'file': 0.34; 'handle': 0.34; 'add': 0.34; 'received:google.com': 0.35; 'best,': 0.35; 'fri': 0.35; 'something': 0.35; 'but': 0.36; 'should': 0.36; 'url:org': 0.36; 'skip:{ 10': 0.36; 'url:non-standard http port': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'say': 0.37; '12,': 0.37; 'late': 0.38; 'several': 0.38; 'why': 0.39; 'does': 0.39; 'skip:- 60': 0.39; 'url:mail': 0.40; 'future': 0.60; 'your': 0.60; 'skip:u 10': 0.61; 'today,': 0.62; 'subject:skip:A 10': 0.63; 'times': 0.63; 'hours': 0.65; 'here': 0.66; 'home': 0.67; 'levels': 0.70; 'yourself,': 0.72; '10%': 0.72; 'august': 0.75; "'for'": 0.84; '--->': 0.84; 'denis': 0.84; 'dic': 0.84; 'dict()': 0.84; 'endeavor': 0.84; 'handing': 0.84; 'plate': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=nGhqAsb25ZQkt8LugNVscFW/ECh4H1LWoXZbog9A8dY=; b=Zy4Cc+h+KEDL69+z1+fGC3ZAx7NsFHtICYbG1RXTYNKWDoQH+f911o+mjWQVp1ivBb eGoaLlttw+qYFpSULCVKHo8w36cyrSkq2B8iKL3z0MCNGPRmxYJLis/IiothMM2xjtOs 4DP2QfueYCig8haue/UvOG1XZNE6VEhTY8BvX6NKeFYZAa6UT/t4MnB8axMt/0/kPDEL AZ/k0JrqqODXlVyqCOd6f5szTOH4fAwCPu/0GWudiXhkaYpqvoXlyjis2f8OqyrdL/u2 bHFDwK8HQk5o022zjQ95mAuo9SuJCMuhZf2erdUDcpJpfbsKOlWWb449ifL90zCzx4z6 060A== |
| MIME-Version | 1.0 |
| X-Received | by 10.112.47.73 with SMTP id b9mr33389175lbn.46.1439416945569; Wed, 12 Aug 2015 15:02:25 -0700 (PDT) |
| In-Reply-To | <201508121725.17249.gheskett@wdtv.com> |
| References | <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CB977D.9080300@mrabarnett.plus.com> <CALa1VB4JP2BZ7zUxqvoq2TJnVMYBVxgABmZPPh6facGK-Yt=jg@mail.gmail.com> <201508121725.17249.gheskett@wdtv.com> |
| Date | Wed, 12 Aug 2015 15:02:25 -0700 |
| Subject | Re: AttributeError |
| From | Ltc Hotspot <ltc.hotspot@gmail.com> |
| To | Gene Heskett <gheskett@wdtv.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.143.1439416953.3627.python-list@python.org> (permalink) |
| Lines | 168 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1439416953 news.xs4all.nl 2923 [2001:888:2000:d::a6]:36779 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:95320 |
Show key headers only | View raw
The problem here is that these are home work assignment and to code an
else word assignment would be in contradiction to the academic
curriculum.
Specifically, I want to deploy a quick and simply dic solution:
Revised code:
c = [0 for i in range(24)]
filename = raw_input("Enter file name: ")
f = open(filename,'r')
for l in f:
h = int(l.strip().split()[X].split(':')[Y])
c[h] = c[h] + 1
f.close()
for i in range(24):
print '{:02d} {}'.format(i, c[i])
---------------------------------------------------------------------------
NameError
Traceback (most recent call last)
C:\Users\vm\Desktop\apps\docs\Python\week_10\assignment_10_2_v_10.py in <module>
()
5 f = open(filename,'r')
6 for l in f:
----> 7 h = int(l.strip().split()[X].split(':')[Y])
8 c[h] = c[h] + 1
9 f.close()
NameError: name 'X' is not defined
In [74]: print X
---------------------------------------------------------------------------
Print X:
NameError
Traceback (most recent call last)
<ipython-input-74-7510f249b93c> in <module>()
----> 1 print X
NameError: name 'X' is not defined
In [75]:
On Wed, Aug 12, 2015 at 2:25 PM, Gene Heskett <gheskett@wdtv.com> wrote:
> On Wednesday 12 August 2015 15:05:37 Ltc Hotspot wrote:
>
>> >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.p
>> >>y 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
>
> After following this thread to late afternoon today, I would say that
> Denis's response was a bit strong and less than helpfull because the
> perceived insult drowns out the true meaning of his remark.
>
> OTOH, _you_ are putting zero effort into understanding the error,
> something the others have encouraged, apparently several times now on at
> least 2 other venues.
>
> This IS how one learns best, by seeing an error and taking an action that
> aleviates the error. Handing the answer to you on a clean plate may fix
> the error, but your chances of understanding why it was fixed are
> perhaps 10% as good than the understanding in the future would be if you
> followed normal debugging proceedures and fixed it yourself.
>
> If you aren't willing to put any effort into it yourself, then perhaps
> Denis does have the right idea. Find another line of endeavor that
> _will_ pay the bills.
>
> Cheers, Gene Heskett
> --
> "There are four boxes to be used in defense of liberty:
> soap, ballot, jury, and ammo. Please use in that order."
> -Ed Howdershelt (Author)
> Genes Web page <http://geneslinuxbox.net:6309/gene>
> --
> https://mail.python.org/mailman/listinfo/python-list
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
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
csiph-web