Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'bindings': 0.09; 'executed': 0.09; 'namespace': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'sure,': 0.09; 'used.': 0.09; 'python': 0.11; 'def': 0.12; 'jan': 0.12; 'wrote': 0.14; 'differs': 0.16; 'foo,': 0.16; 'foo.': 0.16; 'modules.': 0.16; 'namespace.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'statement.': 0.16; 'stuff.': 0.16; 'wrote:': 0.18; 'module': 0.19; '>>>': 0.22; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'refers': 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In- Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'change,': 0.30; "i'm": 0.30; 'code': 0.31; 'once,': 0.31; 'stuff': 0.32; 'themselves': 0.32; 'not.': 0.33; 'subject:from': 0.34; 'could': 0.34; 'but': 0.35; 'there': 0.35; 'instances': 0.36; 'las': 0.37; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'matter': 0.61; 'received:173': 0.61; 'times': 0.62; 'within': 0.65; 'here': 0.66; 'behavior': 0.77; 'batchelder': 0.84; 'bla': 0.84; 'irrelevant': 0.84; 'received:fios.verizon.net': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: SIngleton from __defaults__ Date: Thu, 23 Jan 2014 19:10:17 -0500 References: <26ff768d-349c-48cd-a46f-25343807e18a@googlegroups.com> <52E11AD1.4080305@galileo-press.de> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-254-207.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: 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: 74 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1390522230 news.xs4all.nl 2954 [2001:888:2000:d::a6]:50200 X-Complaints-To: abuse@xs4all.nl X-Original-Bytes: 4696 Path: csiph.com!usenet.pasdenom.info!news.stben.net!border3.nntp.ams.giganews.com!backlog3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Xref: csiph.com comp.lang.python:64644 > Johannes Schneider Wrote in > message: >> On 22.01.2014 20:18, Ned Batchelder wrote: >>> On 1/22/14 11:37 AM, Asaf Las wrote: >>> Chris is right here, too: modules are themselves singletons, no matter >>> how many times you import them, they are only executed once, and the >>> same module object is provided for each import. >> >> I'm not sure, if this is the whole truth. >> >> think about this example: >> >> cat bla.py >> a = 10 >> >> cat foo.py >> from bla import a This makes a a global in foo, bound to 10 >> def stuff(): >> return a This a refers to the global a in foo. >> cat bar.py >> from foo import stuff >> print stuff() >> a = 5 This bar.a is irrelevant to the behavior of stuff. >> print stuff() >> >> from bla import * >> print a >> >> python bar.py >> 10 foo.a == 10 >> 10 foo.a == 10 >> 10 bla.a == 10 >> here the a is coming from bla Twice and is known in the global namespace. There is no global namespace outside of modules. >> the value differs in stuff() No it does not. and before/after the import statement. foo.a does not change. bar.a is never used. >> So the instance of the module differs Nope. Each of the three module instances is constant. The bindings within each could change, but there are no rebinding in the code above. -- Terry Jan Reedy