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


Groups > comp.lang.python > #3571

Re: Namespaces in functions vs classes

Date 2011-04-19 12:47 -0400
Subject Re: Namespaces in functions vs classes
From Gerald Britton <gerald.britton@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.570.1303231664.9059.python-list@python.org> (permalink)

Show all headers | 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