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


Groups > comp.lang.python > #104599

Re: a clarification on the "global" statement sought

From eryk sun <eryksun@gmail.com>
Newsgroups comp.lang.python
Subject Re: a clarification on the "global" statement sought
Date 2016-03-11 03:20 -0600
Message-ID <mailman.8.1457688076.26429.python-list@python.org> (permalink)
References <nbtunf$u4r$1@dont-email.me>

Show all headers | View raw


On Fri, Mar 11, 2016 at 2:13 AM, Charles T. Smith
<cts.private.yahoo@gmail.com> wrote:
> When might a "global" statement be used in the outermost level of a module?

You wouldn't need this in a normal module, because locals and globals
are the same. It may be useful if you're using exec with separate
locals and globals, and need to set a global. For example:

    source = 'global y; x, y = 1, 2'
    gvars, lvars = {}, {}
    exec(source, gvars, lvars)

    >>> lvars
    {'x': 1}
    >>> gvars['y']
    2

Probably you'll never need this.

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


Thread

a clarification on the "global" statement sought "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2016-03-11 08:13 +0000
  Re: a clarification on the "global" statement sought Chris Angelico <rosuav@gmail.com> - 2016-03-11 19:29 +1100
    Re: a clarification on the "global" statement sought "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2016-03-11 08:53 +0000
      Re: a clarification on the "global" statement sought Peter Otten <__peter__@web.de> - 2016-03-11 10:23 +0100
  Re: a clarification on the "global" statement sought Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-11 08:31 +0000
    Re: a clarification on the "global" statement sought "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2016-03-11 09:09 +0000
      Re: a clarification on the "global" statement sought Chris Angelico <rosuav@gmail.com> - 2016-03-11 20:29 +1100
  Re: a clarification on the "global" statement sought eryk sun <eryksun@gmail.com> - 2016-03-11 03:20 -0600

csiph-web