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


Groups > comp.lang.python > #64666

Re: SIngleton from __defaults__

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <johannes.schneider@galileo-press.de>
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; 'amtsgericht': 0.07; 'hrb': 0.07; 'bindings': 0.09; 'executed': 0.09; 'guys.': 0.09; 'namespace': 0.09; 'sure,': 0.09; 'used.': 0.09; 'python': 0.11; 'def': 0.12; 'wrote': 0.14; 'differs': 0.16; 'foo,': 0.16; 'foo.': 0.16; 'modules.': 0.16; 'namespace.': 0.16; 'rainer': 0.16; 'ralf': 0.16; 'reedy': 0.16; 'statement.': 0.16; 'stuff.': 0.16; 'wrote:': 0.18; 'module': 0.19; '>>>': 0.22; 'import': 0.22; 'gmbh': 0.22; 'print': 0.22; 'header:User- Agent:1': 0.23; 'refers': 0.24; 'germany': 0.24; 'header:In-Reply- To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'change,': 0.30; "i'm": 0.30; 'code': 0.31; '>>>>': 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; 'how': 0.40; 'matter': 0.61; 'times': 0.62; 'received:194': 0.64; 'skip:+ 10': 0.65; 'tel.:': 0.65; 'within': 0.65; 'here': 0.66; 'press': 0.70; 'behavior': 0.77; 'batchelder': 0.84; 'bla': 0.84; 'irrelevant': 0.84; 'received:192.168.57': 0.84
Date Fri, 24 Jan 2014 09:20:37 +0100
From Johannes Schneider <johannes.schneider@galileo-press.de>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131103 Icedove/17.0.10
MIME-Version 1.0
To python-list@python.org
Subject Re: SIngleton from __defaults__
References <26ff768d-349c-48cd-a46f-25343807e18a@googlegroups.com> <mailman.5843.1390407541.18130.python-list@python.org> <d4053869-c668-4b5d-8e58-25b3650307df@googlegroups.com> <lbp5hf$vjs$1@ger.gmane.org> <52E11AD1.4080305@galileo-press.de> <lbrhf2$d4u$1@ger.gmane.org> <lbsb0u$7eq$1@ger.gmane.org>
In-Reply-To <lbsb0u$7eq$1@ger.gmane.org>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 8bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5931.1390551625.18130.python-list@python.org> (permalink)
Lines 89
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1390551625 news.xs4all.nl 2859 [2001:888:2000:d::a6]:58551
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:64666

Show key headers only | View raw


thnx guys.

On 24.01.2014 01:10, Terry Reedy wrote:
>>   Johannes Schneider <johannes.schneider@galileo-press.de> 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.
>


-- 
Johannes Schneider
Webentwicklung
johannes.schneider@galileo-press.de
Tel.: +49.228.42150.xxx

Galileo Press GmbH
Rheinwerkallee 4 - 53227 Bonn - Germany
Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax)
http://www.galileo-press.de/

Geschäftsführer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker
HRB 8363 Amtsgericht Bonn

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


Thread

SIngleton from __defaults__ Asaf Las <roegltd@gmail.com> - 2014-01-22 08:07 -0800
  Re: SIngleton from __defaults__ Chris Angelico <rosuav@gmail.com> - 2014-01-23 03:18 +1100
    Re: SIngleton from __defaults__ Asaf Las <roegltd@gmail.com> - 2014-01-22 08:37 -0800
      Re: SIngleton from __defaults__ 88888 Dihedral <dihedral88888@gmail.com> - 2014-01-22 09:23 -0800
      Re: SIngleton from __defaults__ Ned Batchelder <ned@nedbatchelder.com> - 2014-01-22 14:18 -0500
        Re: SIngleton from __defaults__ Asaf Las <roegltd@gmail.com> - 2014-01-22 11:52 -0800
      Re: SIngleton from __defaults__ Johannes Schneider <johannes.schneider@galileo-press.de> - 2014-01-23 14:36 +0100
      Re: SIngleton from __defaults__ Dave Angel <davea@davea.name> - 2014-01-23 11:56 -0500
      Re: SIngleton from __defaults__ Terry Reedy <tjreedy@udel.edu> - 2014-01-23 19:10 -0500
      Re: SIngleton from __defaults__ Johannes Schneider <johannes.schneider@galileo-press.de> - 2014-01-24 09:20 +0100
    Re: SIngleton from __defaults__ Asaf Las <roegltd@gmail.com> - 2014-01-22 13:10 -0800
    Re: SIngleton from __defaults__ Asaf Las <roegltd@gmail.com> - 2014-01-22 14:34 -0800

csiph-web