Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python': 0.09; 'assigning': 0.09; 'convention,': 0.09; 'notation': 0.09; 'operator,': 0.09; 'subject:modules': 0.09; 'programmer': 0.11; 'dictionary.': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'operator.': 0.16; 'overwriting': 0.16; 'subject:class': 0.16; 'subject:instance': 0.16; 'variable.': 0.16; 'variables),': 0.16; 'wrote:': 0.17; 'module': 0.19; 'assignment': 0.22; 'sets': 0.23; 'this:': 0.23; 'thus': 0.24; 'least': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'object,': 0.27; 'dictionary': 0.29; 'keyword': 0.30; 'helpful': 0.30; 'johnson': 0.32; 'to:addr:python-list': 0.33; 'likely': 0.33; 'pm,': 0.35; 'subject:?': 0.35; 'something': 0.35; 'received:org': 0.36; 'but': 0.36; 'message-id:@gmail.com': 0.36; 'useful': 0.36; 'level': 0.37; 'why': 0.37; 'subject:: ': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'header:Received:5': 0.40; 'future.': 0.62; 'helps': 0.63; 'rick': 0.91 X-Virus-Scanned: amavisd-new at torriefamily.org Date: Fri, 08 Feb 2013 21:54:23 -0700 From: Michael Torrie User-Agent: Mozilla/5.0 (X11; Linux i686; rv:10.0.12) Gecko/20130105 Thunderbird/10.0.12 MIME-Version: 1.0 To: python-list@python.org Subject: Re: best way to share an instance of a class among modules? References: <15fe7153-a77a-49eb-9cf8-d4e59b4a2079@z9g2000vbx.googlegroups.com> <5db4add7-ab9c-4311-b3b6-24156cd6f248@z4g2000vbz.googlegroups.com> <5112FC02.1030805@stoneleaf.us> <5b81481d-b7ee-40a2-92ba-4bfb174e1694@googlegroups.com> In-Reply-To: <5b81481d-b7ee-40a2-92ba-4bfb174e1694@googlegroups.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: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1360385670 news.xs4all.nl 6908 [2001:888:2000:d::a6]:39664 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:38497 On 02/07/2013 07:14 PM, Rick Johnson wrote: > So if you want to use "global variables" , (bka: Module level > variables), then simply declare them with a None value like this: > > globalVariable = None This is a nice convention, but at best it's just a helpful notation that helps a programmer know something useful may likely be bound to this name in the future. The '=' sign in Python isn't an assignment operator, at least in this case; it's a binding operator. Thus any future line that sets globalVariable to something isn't assigning a value to this already-declared variable. Instead it's binding the name globalValue to a new object, and overwriting the name in the module dictionary. That's of course why the global keyword is required, so that Python will use the module dictionary instead of the local scope one.