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


Groups > comp.lang.python > #8057

Re: Python scoping

From Ben Finney <ben+python@benfinney.id.au>
Newsgroups comp.lang.python
Subject Re: Python scoping
References <2f69dda9-9532-4fd1-af06-ba85cc2a0e33@v5g2000yqn.googlegroups.com> <87ei2oqaqe.fsf@benfinney.id.au> <mailman.205.1308617759.1164.python-list@python.org>
Date 2011-06-21 12:38 +1000
Message-ID <87aadbrjrh.fsf@benfinney.id.au> (permalink)
Organization Unlimited download news at news.astraweb.com

Show all headers | View raw


Chris Angelico <rosuav@gmail.com> writes:

> On Tue, Jun 21, 2011 at 10:39 AM, Ben Finney <ben+python@benfinney.id.au> wrote:

> > Instead, Python has objects, and references to those objects so you
> > can get at them. The Python documentation, much to my frustration,
> > calls these references “variables” even though that gives exactly
> > the wrong implication of how they'd behave.
>
> But variable names in C and variable names in Python follow fairly
> similar rules.

The names are similar, yes. But names are not variables, and the
conceptual baggage of the term “variable” simply doesn't apply to a
Python identifier.

> Yes, there's the whole thing of automatic sharing and automatic
> deallocation, but the name still follows rules of scoping that are
> very similar - but more flexible in C.

The *binding* is scoped.

> > With the assignment statements (the statements using ‘txt = …’), the
> > name ‘txt’ is bound as a reference to a value. It's not a C-like
> > variable; it doesn't have a type, it doesn't need to be declared,
> > etc. It's just a name, that you can bind to exactly one value any
> > time you like.
>
> It does have a type. It's a Python object.

No, a name is not a Python object, and has no type. A name is simply an
identifier.

> That data type can hold any one "thing". :)

A name refers to an object, it doesn't “hold” anything.

-- 
 \        “… it's best to confuse only one issue at a time.” —Brian W. |
  `\    Kernighan and Dennis M. Ritchie, _The C programming language_, |
_o__)                                                             1988 |
Ben Finney

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


Thread

Python scoping gervaz <gervaz@gmail.com> - 2011-06-20 15:35 -0700
  Re: Python scoping Chris Angelico <rosuav@gmail.com> - 2011-06-21 08:52 +1000
  Re: Python scoping Ben Finney <ben+python@benfinney.id.au> - 2011-06-21 10:39 +1000
    Re: Python scoping Chris Angelico <rosuav@gmail.com> - 2011-06-21 10:55 +1000
      Re: Python scoping Ben Finney <ben+python@benfinney.id.au> - 2011-06-21 12:38 +1000
        Re: Python scoping Chris Angelico <rosuav@gmail.com> - 2011-06-21 13:21 +1000
          Re: Python scoping Ben Finney <ben+python@benfinney.id.au> - 2011-06-21 14:06 +1000
            Re: Python scoping gervaz <gervaz@gmail.com> - 2011-06-21 02:05 -0700
  Re: Python scoping Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-21 00:57 +0000

csiph-web