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


Groups > comp.lang.python > #3571

Re: Namespaces in functions vs classes

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <gerald.britton@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'instance': 0.05; 'python': 0.07; 'correct.': 0.09; 'definitions.': 0.09; 'namespace': 0.09; 'wrote:': 0.14; 'global,': 0.16; 'lookup': 0.16; 'subject:Namespaces': 0.16; 'subject:classes': 0.16; 'to:name :python-list (general)': 0.16; 'to:2**1': 0.20; 'received:209.85.220': 0.26; 'classes': 0.26; 'function': 0.27; 'message-id:@mail.gmail.com': 0.28; 'helpful': 0.29; 'definition': 0.29; 'class': 0.29; 'all.': 0.30; 'does': 0.31; 'however,': 0.31; 'separate': 0.31; 'to:addr:python-list': 0.32; 'received:209.85': 0.37; 'received:google.com': 0.38; 'to:addr:python.org': 0.39; 'received:209': 0.39; 'would': 0.40; 'header:Received:5': 0.40; 'local,': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to :content-type; bh=93CAg5ci6Vdqd38cG2gIvMw6xDyGkpyK6C4ZcCuiA0I=; b=knuOA6Eu8GB6bPNr1BHqCda3ml9OS30E1Vmc8UtJCmWH5WcxpedHoLDxM+6vUBAIvs FMQEBwzn12LzIYB5TvjAZUTE6UGTQHERe0MN4MNB4Jru0cpqhjnzbXe6giFq2fNGq+4V HXHD48y8FCLtOwqUoN4KPmqfLnPOckhMW2GgA=
DomainKey-Signature a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=g3KLd39YjsT0+K8CgZL6RT6Pl5aoTG+nXXMW1kmi4BKfZ9DsiSPWkGIXoxW7ptsg1K cKyoXHqQtHsbURmaddAjh6QSWuvGgXrTk06l82ag6+vnahaMNhzE7cdO0mWDkPAHZkbH 9MXJiknFQgs7TUEmrYGxSzUpiuBipzZtE9nEw=
MIME-Version 1.0
Date Tue, 19 Apr 2011 12:47:40 -0400
Subject Re: Namespaces in functions vs classes
From Gerald Britton <gerald.britton@gmail.com>
To Ethan Furman <ethan@stoneleaf.us>, "python-list (General)" <python-list@python.org>
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.570.1303231664.9059.python-list@python.org> (permalink)
Lines 19
NNTP-Posting-Host 82.94.164.166
X-Trace 1303231665 news.xs4all.nl 81485 [::ffff:82.94.164.166]:33120
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:3571

Show key headers only | View raw


>Gerald Britton wrote:
>> I now understand the Python does
>> not consider a class definition as a separate namespace as it does for
>> function definitions.  That is a helpful understanding.

>That is not correct.  Classes are separate namespaces -- they just
>aren't automatically searched.  The only namespaces that are
>automatically searched are local, non-local, global, and built-in.

I see you misunderstood my observation:  Python does not consider a class
definition as a separate namespace *as it does* for function definitions.

Of course classes are separate namespaces, or they would not work at
all.  However,
Python does not automatically search class namespaces -- even within the class
definition -- *as it does* within function definitions.

That is the key insight I was seeking.  To search a class namespace one must
qualify the lookup with the class or instance name.

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


Thread

Re: Namespaces in functions vs classes Gerald Britton <gerald.britton@gmail.com> - 2011-04-19 12:47 -0400
  Re: Namespaces in functions vs classes "Rhodri James" <rhodri@wildebst.demon.co.uk> - 2011-04-19 23:00 +0100
    Re: Namespaces in functions vs classes Chris Angelico <rosuav@gmail.com> - 2011-04-20 08:11 +1000
    [OT] Piling of prepositions (was: Namespaces in functions vs classes) Ben Finney <ben+python@benfinney.id.au> - 2011-04-20 09:39 +1000
      Re: [OT] Piling of prepositions (was: Namespaces in functions vs classes) Dave Angel <davea@ieee.org> - 2011-04-19 22:49 -0400
      Re: [OT] Piling of prepositions (was: Namespaces in functions vs classes) geremy condra <debatem1@gmail.com> - 2011-04-19 20:59 -0700

csiph-web