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


Groups > comp.lang.python > #31046

Re: surprising behaviour of global dictionaries

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <d@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'subsequent': 0.04; 'cache': 0.05; 'key.': 0.07; '"a"': 0.09; 'before.': 0.09; 'imports': 0.09; 'subtle': 0.09; 'cc:addr:python-list': 0.10; '"b"': 0.16; 'subject:dictionaries': 0.16; 'sys.modules': 0.16; 'wrote:': 0.17; 'instance': 0.17; 'library,': 0.17; 'module,': 0.17; "shouldn't": 0.17; 'import': 0.21; 'thanks.': 0.21; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'script': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'common': 0.26; 'am,': 0.27; 'usually': 0.30; 'code': 0.31; 'another': 0.33; 'third': 0.34; 'there': 0.35; 'but': 0.36; 'should': 0.36; 'october': 0.37; 'one,': 0.37; 'why': 0.37; 'subject:: ': 0.38; 'received:192': 0.39; 'received:192.168': 0.40; 'your': 0.60; 'real': 0.61; 'more': 0.63; 'behavior': 0.64; 'header:Reply-To:1': 0.68; 'received:74.208': 0.71; 'reply-to:no real name:2**0': 0.72; 'cycles.': 0.84; 'otten': 0.84; 'seriously,': 0.91
Date Tue, 09 Oct 2012 12:10:40 -0400
From Dave Angel <d@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0
MIME-Version 1.0
To Michele Simionato <michele.simionato@gmail.com>
Subject Re: surprising behaviour of global dictionaries
References <40ac555b-71c2-445e-814b-6bd1d037dbee@googlegroups.com> <mailman.2006.1349796256.27098.python-list@python.org> <b8a3d0c5-d6ba-42ef-a706-708b9148b594@googlegroups.com>
In-Reply-To <b8a3d0c5-d6ba-42ef-a706-708b9148b594@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:SEdOFujiRw9zkhXq+fVPb7pq7eKc1zsXBR3aWdIYKMN Q0z5ezNOosgacUAIjw54NExRPlNMmCjOAy/yzp1MWr9tw3acNj QRlqt+qHARYlxeJl//mRPHDyYLrYaeCXqcqbY7USGNqVrl4B+1 eyQvFM935yaRg5n1JVQebAo9RlyyJn+UM7BcdzxBy3jvSc/jNK AxElIwg3u6LfNpCEPipg8VvN1Pr8QiNYELoWt5MQLsEL5+cYKB AIznSOtg0FGtxRT9WD/4gtWiDgMhrlJtxFgkJ96zcT8C4ByJH+ zJc3PwP+D3gXhEX4iJBhpbLcuZLgnKC8ZmLixg8s3JZntKwbA= =
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To d@davea.name
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2009.1349799062.27098.python-list@python.org> (permalink)
Lines 23
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1349799062 news.xs4all.nl 6986 [2001:888:2000:d::a6]:53087
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:31046

Show key headers only | View raw


On 10/09/2012 11:36 AM, Michele Simionato wrote:
> On Tuesday, October 9, 2012 5:24:17 PM UTC+2, Peter Otten wrote:
>> Seriously, you shouldn't use the main script as a library; it is put into 
>>
>> the sys.modules cache under the "__main__" key. Subsequent imports under its 
>>
>> real name will not find that name in the cache and import another instance 
>>
>> of the module, with puzzling effects
> Actually I usually never use the main script as a library, this is why I never experience this puzzling behavior before. But now it is clear, thanks.
More generally, you should arrange your imports so that there are no
cycles.  If module/script "a" imports "b", directly or indirectly, "b"
should not try to import "a."  Move the common code to a third place,
and import it from both "a" and from "b".

The other symptoms you can get are more subtle than this one, but just
as surprising.


-- 

DaveA

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


Thread

surprising behaviour of global dictionaries Michele Simionato <michele.simionato@gmail.com> - 2012-10-09 08:08 -0700
  Re: surprising behaviour of global dictionaries Peter Otten <__peter__@web.de> - 2012-10-09 17:24 +0200
    Re: surprising behaviour of global dictionaries Michele Simionato <michele.simionato@gmail.com> - 2012-10-09 08:36 -0700
      Re: surprising behaviour of global dictionaries Dave Angel <d@davea.name> - 2012-10-09 12:10 -0400
    Re: surprising behaviour of global dictionaries Michele Simionato <michele.simionato@gmail.com> - 2012-10-09 08:36 -0700
    Re: surprising behaviour of global dictionaries Grant Edwards <invalid@invalid.invalid> - 2012-10-09 15:53 +0000
      Re: surprising behaviour of global dictionaries Peter Otten <__peter__@web.de> - 2012-10-09 19:45 +0200

csiph-web