Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.023 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'initialize': 0.07; 'oh,': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'caching': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'func():': 0.16; 'likewise': 0.16; 'new:': 0.16; 'subject: \n ': 0.16; 'subject:bound': 0.16; 'wrote:': 0.18; 'dependent': 0.19; 'import': 0.22; 'cc:addr:python.org': 0.22; 'instance,': 0.24; 'math': 0.24; 'cc:2**0': 0.24; 'this:': 0.26; 'header:In-Reply- To:1': 0.27; 'idea': 0.28; 'point': 0.28; 'function': 0.29; 'dec': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'subject:About': 0.31; 'subject:what': 0.31; 'this.': 0.32; 'fri,': 0.33; 'could': 0.34; 'subject: (': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'scheme': 0.36; 'so,': 0.37; 'pm,': 0.38; 'skip:u 10': 0.60; 'strictly': 0.61; 'happen': 0.63; 'our': 0.64; 'subject:The': 0.64; 'different': 0.65; 'guaranteed': 0.75; 'subject:gets': 0.84; 'to:none': 0.92; 'serious': 0.97 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=b+jJKx5en5TDQhDpt/vFg0Kho+EpSYHiGBf0tjlRWYQ=; b=Lvejq+B2qya3OupdfZn0rIBQwzOM0km10bXco9WFYh8mu/dv3wQBSEuzW6drRHdLYy /vxE5XgTXX7EEy8FfghDieE9ud/KsrnY9HfYqkJbBslzz6rvsPhjn7tlffxxQ+T7eiaD DumY0/6tM2dDRxlGaN64kzz3WSo/ksy5UdFw4Gud4xuZE89mXd+Iyeo+yJdZmkvk2SR6 SSzr/ljE8SR2PbT4PY33CIXpZKY5c/Z15C9R7B48P6oh3/Mk/A7f8GK/KKrsXOeG/gTz +gsXzV8rQbTJd/a94t8WQLhm9J0H5/qszuMSXRVgZquCjXfWenK2HwtiVAYRTNC76+GA VG7Q== MIME-Version: 1.0 X-Received: by 10.50.62.104 with SMTP id x8mr1679421igr.2.1417773784407; Fri, 05 Dec 2014 02:03:04 -0800 (PST) In-Reply-To: <548180ae$0$13007$c3e8da3$5496439d@news.astraweb.com> References: <548113f3$0$13003$c3e8da3$5496439d@news.astraweb.com> <548180ae$0$13007$c3e8da3$5496439d@news.astraweb.com> Date: Fri, 5 Dec 2014 21:03:04 +1100 Subject: Re: The binding operator, and what gets bound to what (was: About Modifying Globals) From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1417773792 news.xs4all.nl 2957 [2001:888:2000:d::a6]:41717 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:81993 On Fri, Dec 5, 2014 at 8:53 PM, Steven D'Aprano wrote: > Oh, I learned something new: strictly speaking, this is implementation- > dependent and not guaranteed to work in the future! > > def func(): > global math > import math When would you actually *want* this, though? Given that 'import' already caches, there's not much point caching globally, and the idea that a function could cause a module-level import to happen is pretty weird! The only scheme I could concoct would be something like this: def use_foo(): global useme import foo as useme # code to initialize foo for our use def use_bar(): global useme import bar as useme # likewise def do_stuff(): useme.blah(1,2,3,4) So, for instance, if you need a JavaScript executor, you might support several different runtimes, and allow one to be selected like this. But this would be serious code smell. ChrisA