Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #95326

Re: AttributeError

Path csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
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; 'data:': 0.07; 'f.close()': 0.07; 'defined.': 0.09; 'nameerror:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'snippet': 0.09; 'splitting': 0.09; 'python.': 0.11; 'jan': 0.11; 'wed,': 0.15; 'labels,': 0.16; 'means.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'wrote:': 0.16; '>>>': 0.20; '2015': 0.20; 'aug': 0.20; 'posted': 0.21; 'produces': 0.22; 'strip': 0.22; 'defined': 0.23; 'this:': 0.23; 'header:In-Reply- To:1': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints- To:1': 0.26; 'error': 0.27; 'define': 0.27; 'whitespace': 0.29; 'print': 0.30; 'url:mailman': 0.30; 'code': 0.30; "can't": 0.32; 'url:python': 0.33; 'right?': 0.33; 'sat': 0.33; 'open': 0.33; 'url:listinfo': 0.34; 'file': 0.34; 'handle': 0.34; 'add': 0.34; 'so,': 0.35; 'text': 0.35; 'fri': 0.35; 'label': 0.35; 'url:org': 0.36; 'skip:{ 10': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; '12,': 0.37; 'difference': 0.38; 'url:mail': 0.40; 'to:addr:python.org': 0.40; 'where': 0.40; 'your': 0.60; 'charset:windows-1252': 0.62; 'subject:skip:A 10': 0.63; 'between': 0.65; 'reviewed': 0.72; 'received:12': 0.81; '--->': 0.84; 'denis': 0.84; 'dict()': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Emile van Sebille <emile@fenx.com>
Subject Re: AttributeError
Date Wed, 12 Aug 2015 16:15:14 -0700
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>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host www.westernstatesglass.com
User-Agent Mozilla/5.0 (Windows NT 6.2; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0
In-Reply-To <CALa1VB4_4vvRNWRW90JZKrcSY8_E-DZ6ESL+_iRKrMP7nJhEdg@mail.gmail.com>
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.149.1439421327.3627.python-list@python.org> (permalink)
Lines 80
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1439421327 news.xs4all.nl 2898 [2001:888:2000:d::a6]:57863
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:95326

Show key headers only | View raw


On 8/12/2015 4:05 PM, Ltc Hotspot wrote:
> On Wed, Aug 12, 2015 at 3:35 PM, MRAB <python@mrabarnett.plus.com> wrote:
>> On 2015-08-12 22:16, Denis McMahon wrote:
>> [snip]
>>
>>> c = [0 for i in range(24)]
>>> 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])
>>>
>> There's no need to strip whitespace just before splitting on it.
>>
>> This:
>>
>>      l.strip().split()
>>
>> can be shortened to this:
>>
>>      l.split()
>>
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>
>
> MRAB,
>
> The Revised code produces a traceback:
> ()
>        9
>       10 c = [0 for i in range(24)]
> ---> 11 f  = open(filename,'r')
>       12 for l in f:
>       13      h = int(l.split()[X].split(':')[Y])
>
> NameError: name 'filename' is not defined

So, read your posted code below and tell us where the label 'filename' 
is defined.  We can't find it.  Neither can python.  That's what the 
error message means.  Was that not clear?  You do understand the 
difference between text and labels, right?  You have by now reviewed the 
tutorial?

Emile


>
>
>
> The 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: ")# Add Snippet file
> #handle = open (fname, 'r')# Add Snippet file
>
> c = [0 for i in range(24)]
> f  = open(filename,'r')
> for l in f:
>       h = int(l.split()[X].split(':')[Y])
>       c[h] = c[h] + 1
> f.close()
> for i in range(24):
>       print '{:02d} {}'.format(i, c[i])
>
>
> How do I define the file name in order to remove the traceback?
>
> Regards,
> Hal
>

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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