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


Groups > comp.lang.python > #6565

Re: scope of function parameters

References (1 earlier) <mailman.2217.1306662671.9059.python-list@python.org> <4de24045$0$29996$c3e8da3$5496439d@news.astraweb.com> <BANLkTinK=dHCbocURD2+s5uvdonBkS+uFQ@mail.gmail.com> <BANLkTimWP+jP0s5DsBaFbv6LV5OTYA8hQw@mail.gmail.com> <BANLkTikL=mf+XfXincqHn--WsXaowEpyng@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2011-05-29 13:12 -0600
Subject Re: scope of function parameters
Newsgroups comp.lang.python
Message-ID <mailman.2234.1306696367.9059.python-list@python.org> (permalink)

Show all headers | View raw


On Sun, May 29, 2011 at 12:38 PM, Chris Angelico <rosuav@gmail.com> wrote:
> I thought it basically functioned top-down. You get a different error
> on the print line if there's a "bar = 42" *after* it. This could make
> debugging quite confusing.
>
> Guess it's just one of the consequences of eschewing variable
> declarations. Sure it's easier, but there's complications down the
> road.

It's also a consequence of local variable access being optimized with
different bytecode: the type of storage has to be determined at
compile time.  The compiler could in principle figure out that "bar"
cannot be bound at that point and make it a global reference, but it
is easy to concoct situations involving loops or conditionals where
the storage cannot be determined at compile time, and so the compiler
follows the simple rule of making everything local unless it's never
assigned.

Cheers,
Ian

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


Thread

Re: scope of function parameters Wolfgang Rohdewald <wolfgang@rohdewald.de> - 2011-05-29 11:47 +0200
  Re: scope of function parameters Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-29 12:47 +0000
    Re: scope of function parameters Chris Angelico <rosuav@gmail.com> - 2011-05-30 03:53 +1000
      Re: scope of function parameters Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-29 18:28 +0000
    Re: scope of function parameters Chris Rebert <clp2@rebertia.com> - 2011-05-29 11:01 -0700
    Re: scope of function parameters Chris Angelico <rosuav@gmail.com> - 2011-05-30 04:38 +1000
      Re: scope of function parameters Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-29 18:53 +0000
        Re: scope of function parameters Chris Angelico <rosuav@gmail.com> - 2011-05-30 05:20 +1000
    Re: scope of function parameters Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-29 13:12 -0600

csiph-web