Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #95341
| References | (13 earlier) <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 | 2015-08-13 02:41 -0700 |
| Subject | Re: AttributeError |
| From | Ltc Hotspot <ltc.hotspot@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.165.1439458918.3627.python-list@python.org> (permalink) |
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