Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #95341
| Path | csiph.com!news.mixmin.net!feeder1.xsusenet.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.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'data:': 0.07; 'f.close()': 0.07; 'val': 0.07; 'cc:addr:python-list': 0.09; 'lst': 0.09; 'nameerror:': 0.09; 'snippet': 0.09; 'splitting': 0.09; 'timestamp': 0.09; 'jan': 0.11; 'index': 0.13; 'wed,': 0.15; 'file,': 0.15; 'thu,': 0.15; '":"': 0.16; 'handle:': 0.16; 'hh:mm:ss': 0.16; 'line.split()': 0.16; 'wrote:': 0.16; 'tells': 0.18; 'programmer': 0.18; 'input': 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'aug': 0.20; 'posted': 0.21; 'are.': 0.22; 'assumes': 0.22; 'pos': 0.22; 'am,': 0.23; 'appears': 0.23; 'defined': 0.23; 'absolute': 0.23; 'elements': 0.23; 'insert': 0.23; 'split': 0.23; 'words': 0.24; 'header:In- Reply-To:1': 0.24; 'define': 0.27; 'message-id:@mail.gmail.com': 0.27; 'time:': 0.27; 'values': 0.28; 'actual': 0.28; 'record': 0.29; '-0700,': 0.29; '13,': 0.29; 'key,': 0.29; 'solution,': 0.29; 'print': 0.30; 'code': 0.30; 'post': 0.31; 'returned': 0.32; 'getting': 0.33; 'common': 0.33; 'sat': 0.33; 'traceback': 0.33; 'open': 0.33; 'file': 0.34; 'handle': 0.34; 'add': 0.34; 'lists': 0.34; 'received:google.com': 0.35; 'text': 0.35; 'follows:': 0.35; 'fri': 0.35; 'replace': 0.35; 'there': 0.36; 'lines': 0.36; 'data.': 0.36; 'subject:: ': 0.37; 'represent': 0.38; 'why': 0.39; 'data': 0.39; 'your': 0.60; 'subject:skip:A 10': 0.63; 'positions': 0.64; 'hours': 0.65; 'explanations': 0.72; '--->': 0.84; 'denis': 0.84; 'dict()': 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=EHWmw9wuFYQbgIoRfDm+9+bQeT8BG5CNg7H7tf0ejjU=; b=SH5mzwTeWU+rvUE8HDwaBW1idCGgj8JPBPJ4d6OzxTrvviBFK2SZ6p+8G4DmXipZrd RZCKptbY1DKvNAuCBHzkHSIIIOBmlsBLWpf24oCNNscaDH5cdstp7UDDWc3LmzCZiy0I mvcmHDLcWxg1Dvsj99k4zr7otNYEpswD74sWf9hWPScBJR3XflYoTAhB4cQO0msxL2Nr xpPkAQLWdQKDw8jedCZ7rz9w8eZxAFGngi1ZQWshfRanKT5UW0weQiMtfVvrJU1tpCMT UtsW8AW9HT/wNwf6t61V05KPLPkQofC6Zaw5GYmdIHmmikpqUMYs2pRN+qceHNG1oXtC CYJw== |
| MIME-Version | 1.0 |
| X-Received | by 10.152.10.97 with SMTP id h1mr35907451lab.45.1439458915364; Thu, 13 Aug 2015 02:41:55 -0700 (PDT) |
| In-Reply-To | <mqhn78$f58$1@dont-email.me> |
| References | <0baa3bd5-9f80-4d4e-9367-84e2a32d8c70@googlegroups.com> <55CA92BA.7070905@mrabarnett.plus.com> <CALa1VB7f1-4Jrp+FCXEY5oCES+epXzMLLNatB_uiiZ2X7=8pPw@mail.gmail.com> <mailman.94.1439341104.3627.python-list@python.org> <103ea014-9bdb-4c37-acd1-cdc64f5f721e@googlegroups.com> <mqfq0t$8np$2@dont-email.me> <3f132c37-bdb5-4313-9285-69e094392ccf@googlegroups.com> <55CB7823.8010402@mrabarnett.plus.com> <CALa1VB52wjJesc8Skp=Uiu9fY-NMvfd8cPVEpnkxdX-22+xO6w@mail.gmail.com> <55CB815B.8070800@mrabarnett.plus.com> <mailman.131.1439401060.3627.python-list@python.org> <5a09701f-06d3-42dd-aa96-59920de76044@googlegroups.com> <mqgd3p$8np$5@dont-email.me> <55CBCA4D.1010706@mrabarnett.plus.com> <CALa1VB4_4vvRNWRW90JZKrcSY8_E-DZ6ESL+_iRKrMP7nJhEdg@mail.gmail.com> <55CBD3DE.2080407@mrabarnett.plus.com> <mailman.151.1439423194.3627.python-list@python.org> <mqhn78$f58$1@dont-email.me> |
| Date | Thu, 13 Aug 2015 02:41:55 -0700 |
| Subject | Re: AttributeError |
| From | Ltc Hotspot <ltc.hotspot@gmail.com> |
| To | Denis McMahon <denismfmcmahon@gmail.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.165.1439458918.3627.python-list@python.org> (permalink) |
| Lines | 68 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1439458918 news.xs4all.nl 2879 [2001:888:2000:d::a6]:58784 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:95341 |
Show key headers only | View raw
On Thu, Aug 13, 2015 at 2:15 AM, Denis McMahon <denismfmcmahon@gmail.com> wrote:
> On Wed, 12 Aug 2015 16:46:32 -0700, Ltc Hotspot wrote:
>
>> How do I define X?
>>
> -------------------------------------------------------------------------------------
>> Traceback reads:
>>
>> 10 f = open(filename,'r')
>> 11 for l in f:
>> ---> 12 h = int(l.split()[X].split(':')[Y])
>> 13 c[h] = c[h] + 1 14 f.close()
>>
>> NameError: name 'X' is not defined
>
> If you read the text that I posted with the solution, it tells you what X
> and Y are. They are numbers that describe the positions of elements in
> your input data.
>
> This absolute refusal by you to read any explanations that are posted are
> exactly why you will never be a good programmer. To become a good
> programmer you need to read and understand the explanations.
>
> In the post with that code example, I wrote:
>
> It also assumes that there is a timestamp of the form hh:mm:ss that
> always appears at the same word position X in each line in the file, and
> that the hours record always at position Y in the timestamp.
>
> You have to replace X and Y in that line with numbers that represent the
> positions in the lists returned by the relevant split commands of the
> actual text elements that you want to extract.
>
> --
Denis,
What are the values of X & Y from the code as follows:
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 # to add snippet file data
#handle = open (fname, 'r')# insert # to add snippet file data
for line in handle:
if line.startswith("From "):
time = line.split() # splitting the lines ->
# print time: ['From', 'stephen.marquard@uct.ac.za', 'Sat',
'Jan', '5', '09:14:16', '2008']
for hours in time: #getting the index pos of time ->
hours = line.split(":")[2] # splitting on ":" ->
line = line.rstrip()
count[hours] = count.get(hours, 0) + 1 # getting the index pos of hours.
lst = [(val,key) for key,val in count.items()] # find the most common words
lst.sort(reverse=True)
for key, val in lst[:12] :
print key, val
Regards,
Hal
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