Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: eryk sun Newsgroups: comp.lang.python Subject: Re: a clarification on the "global" statement sought Date: Fri, 11 Mar 2016 03:20:32 -0600 Lines: 18 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de 1AuKZC7lmP2sTL+MqRmX2gjITtoIOTmAeZuTJ8A0JMSg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'received:209.85.223': 0.03; 'subject:skip:c 10': 0.07; 'globals': 0.09; '{},': 0.09; 'example:': 0.10; '"global"': 0.16; '2016': 0.16; 'module?': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; "wouldn't": 0.16; 'module,': 0.18; '>>>': 0.20; 'cc:2**0': 0.20; 'exec': 0.22; 'am,': 0.23; 'cc:addr:gmail.com': 0.24; 'header:In- Reply-To:1': 0.24; 'fri,': 0.27; 'separate': 0.27; 'message- id:@mail.gmail.com': 0.27; 'this.': 0.28; 'probably': 0.31; 'statement': 0.32; 'useful': 0.33; 'source': 0.33; 'received:google.com': 0.35; 'level': 0.35; 'received:209.85': 0.36; 'subject:" ': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:209': 0.38; 'subject:the': 0.39; 'to:addr:python.org': 0.40; "you'll": 0.61; 'mar': 0.65; 'smith': 0.76; 'locals': 0.84; 'outermost': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=+VPomapgtrbO3+sf5LIb2ZRTrUVTav09ZH8hW7F0DgM=; b=a9Brq/j24EgIEUh95k0UNFDUSnv6ZJWqVw/i6deQVk/Rgf1gA1roP98OCa3ZneCx08 NSMg7FgebVvZWr9FYHtDUT2er7g01BpvKRV/+x1n1BQr2yhW96C+98Kf4kPpeMQsZn/H sOgFgHsbizDDA87P4gyJWoLrQvwQNeeU0RmUEQ+cQunsasgR/JMeqEc+NbgehB9glfdp IQeD/E/ccd/iyUj+FV2kGhWf1et9Y2Lqzyp0qwZULKs82qfZRBaP/ixbB+Vyja1moIK+ MfLY5t9fqEdLFdysOiFhl2YPEjigtqaxf7p9OQ0wB72y3RlvYRCoG5vaGgx64LrR9LYi Gkjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=+VPomapgtrbO3+sf5LIb2ZRTrUVTav09ZH8hW7F0DgM=; b=BVFNyo/f1vDlgDZ93YSAKjhOkr/R/kcpxKt4ftOaEvFMCoxchpONk9U3gg0xkiULu7 +ofi6RBj3Wo7bbXFV9dYYq7yS50Ji5unAr3tlKmnDNQws3lYfdtpGBmY8WXM/QIJgluj PrxdV0ffoc6FXdIYQuHXHUPwrXHuFt4n7bvFKDg4GxWdE2C7UrtHKoqNxnXgGh4zRCZh bQNZ29XNXGnwtBWVxTPkZfIQraNy2tDiSAna21nC8BS6H7spQKIDMDZ3g4xlW3COTM/w 5VaQDsoglo3oanw/paY8ZHOdrb6bOGNFY5WJRS/tXgvYy9BbOD+7aW17XhwQGCoN7cgQ FkHg== X-Gm-Message-State: AD7BkJLRZk8gFj+JOxmbnOyLAaNwQnp0ZVj0e/A3MVC6f0MUrTVdA4DfHjO5vLxlNmQIIjbemSbsnwUCNU60JA== X-Received: by 10.107.135.202 with SMTP id r71mr9954061ioi.103.1457688072353; Fri, 11 Mar 2016 01:21:12 -0800 (PST) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:104599 On Fri, Mar 11, 2016 at 2:13 AM, Charles T. Smith 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.