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


Groups > comp.lang.python > #34099

Re: amazing scope?

References <mailman.380.1354273891.29569.python-list@python.org> <thhmo9-ie6.ln1@satorlaser.homedns.org> <CAF_E5JbeoJ__WTMy-omFPrWP23E=yyeEJ8ABaEJ5jaFP9vFbPw@mail.gmail.com>
Date 2012-12-01 03:08 +1100
Subject Re: amazing scope?
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.385.1354291733.29569.python-list@python.org> (permalink)

Show all headers | View raw


On Sat, Dec 1, 2012 at 3:05 AM, andrea crotti <andrea.crotti.0@gmail.com> wrote:
> Well I knew that this works fine, even if I feel a bit guilty to do
> this, and better is:
>
> foo = 'bar' if some_condition else 'baz'
>
> Anyway for me the suprise is that something that is defined *later* at
> the module scope is found in a function which is defined *earlier*.

It's assigned to earlier. It's no different from C code like this:

int foo;

void blah()
{
    /* do stuff with foo */
}

int main()
{
    foo = 1;
}


In Python, the "int foo;" is implicit, but the scope is the same.

ChrisA

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


Thread

amazing scope? andrea crotti <andrea.crotti.0@gmail.com> - 2012-11-30 11:11 +0000
  Re: amazing scope? Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-11-30 12:23 +0100
    Re: amazing scope? andrea crotti <andrea.crotti.0@gmail.com> - 2012-11-30 16:05 +0000
    Re: amazing scope? Chris Angelico <rosuav@gmail.com> - 2012-12-01 03:08 +1100
    Re: amazing scope? Dave Angel <d@davea.name> - 2012-11-30 17:57 -0500

csiph-web