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


Groups > comp.lang.python > #68216

Re: Closure/method definition question for Python 2.7

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.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.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.06; 'assign': 0.07; 'latter': 0.09; 'raises': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:2.7': 0.09; 'subject:method': 0.09; 'subject:question': 0.10; 'def': 0.12; 'defined.': 0.16; 'hides': 0.16; 'nameerror:': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'scope.': 0.16; 'self.y': 0.16; 'variable.': 0.16; 'ways:': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'header:User-Agent:1': 0.23; '---': 0.24; 'subject:/': 0.26; 'header:X-Complaints-To:1': 0.27; 'class': 0.32; 'skip:_ 10': 0.34; 'module.': 0.36; 'charset:us-ascii': 0.36; 'two': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'read': 0.60; 'new': 0.61; "you'll": 0.62; 'name': 0.63; 'refer': 0.63; 'or:': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Neil Cerutti <neilc@norwich.edu>
Subject Re: Closure/method definition question for Python 2.7
Date Tue, 11 Mar 2014 13:20:35 +0000 (UTC)
Organization Norwich University
References <mailman.8014.1394472539.18130.python-list@python.org> <87vbvmq7l3.fsf@elektro.pacujo.net>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host jackman.norwich.edu
User-Agent slrn/0.9.9p1/mm/ao (Win32)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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.8046.1394544066.18130.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1394544066 news.xs4all.nl 2917 [2001:888:2000:d::a6]:59053
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:68216

Show key headers only | View raw


On 2014-03-10, Marko Rauhamaa <marko@pacujo.net> wrote:
> "Brunick, Gerard:(Constellation)" <Gerard.Brunick@constellation.com>:
>
>> class Test(object):
>>     x = 10
>>
>>     def __init__(self):
>>         self.y = x
>>
>> t = Test()
>> ---
>>
>> raises
>>
>> NameError: global name 'x' is not defined.
>
> In the snippet, x is neither local to __init__() nor global to
> the module. It is in the class scope. You can refer to it in
> one of two ways:
>
>    Test.x
>
> or:
>
>    self.x

The latter will work only to read the class variable. If you
assign to self.x you'll create a new instance variable that hides
the class variable.

-- 
Neil Cerutti

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


Thread

Closure/method definition question for Python 2.7 "Brunick, Gerard:(Constellation)" <Gerard.Brunick@constellation.com> - 2014-03-10 17:27 +0000
  Re: Closure/method definition question for Python 2.7 Marko Rauhamaa <marko@pacujo.net> - 2014-03-10 19:36 +0200
    Re: Closure/method definition question for Python 2.7 Neil Cerutti <neilc@norwich.edu> - 2014-03-11 13:20 +0000

csiph-web