Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.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.031 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'received:134': 0.05; 'modified': 0.07; 'tries': 0.07; 'variables': 0.07; "module's": 0.16; 'subject:non': 0.16; 'variable.': 0.16; 'obviously': 0.18; 'seems': 0.21; 'import': 0.22; 'header:User-Agent:1': 0.23; 'case.': 0.24; 'earlier': 0.24; '(or': 0.24; 'sort': 0.25; 'possibly': 0.26; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'program,': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'problem': 0.35; 'anywhere': 0.35; 'classes': 0.35; 'possible.': 0.35; 'subject:skip:d 10': 0.36; 'subject:?': 0.36; 'changing': 0.37; 'too': 0.37; 'easily': 0.37; 'being': 0.38; 'sometimes': 0.38; 'whatever': 0.38; 'to:addr :python-list': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'called': 0.40; 'took': 0.61; 'first': 0.61; 'show': 0.63; 'name': 0.63; 'here': 0.66; 'between': 0.67; 'nobody': 0.68; 'pardon': 0.84 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ap8EAFPFEVKGuA9G/2dsb2JhbABbwEuCdIE3gxkBBXgRCyEWDwkDAgECAUUTCAKIDK1AiAeQZxaDfAOXZIYWiz+DHg Date: Mon, 19 Aug 2013 09:14:05 +0200 From: Antoon Pardon User-Agent: Mozilla/5.0 (X11; Linux i686; rv:10.0.12) Gecko/20130116 Icedove/10.0.12 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Importing variables non-deterministic? References: <520f9054$0$30000$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <520f9054$0$30000$c3e8da3$5496439d@news.astraweb.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1376896513 news.xs4all.nl 15937 [2001:888:2000:d::a6]:54240 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52674 Op 17-08-13 17:01, Steven D'Aprano schreef: > > And here you re-import the name "y" from struct_global. That rebinds the > current module's "y" with whatever value struct_global.y has *now*, > rather than a second (or a minute, or an hour) earlier when the first > import took place. Obviously at some point between the first import and > the second import, struct_global.y must have been reassigned from -1 to > 62. > > This goes to show why global variables are considered harmful, and why > clean, modern program design tries to reduce the use of them as much as > possible. Global variables are too easily modified by, well, *anything*. > The sort of behaviour you are seeing is sometimes called "action at a > distance" -- something, anything, anywhere in your program, possibly > buried deep, deep down inside some function you might never suspect, is > changing the global variable. I think you are overstating your case. Classes and functions are variables too and in general nobody seems to have a problem with them being global. -- Antoon Pardon