Path: csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!bcyclone01.am1.xlned.com!bcyclone01.am1.xlned.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'puts': 0.07; 'subject:How': 0.09; 'foo,': 0.09; 'imported': 0.09; 'imports': 0.09; 'to)': 0.09; 'variables,': 0.09; 'variables': 0.15; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'ivan': 0.16; "module's": 0.16; 'namespace.': 0.16; 'picks': 0.16; 'simple.': 0.16; 'subject:variable': 0.16; 'wrote:': 0.16; 'fairly': 0.22; 'code.': 0.23; '(or': 0.23; 'references': 0.23; 'this:': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'header:User-Agent:1': 0.26; 'forgive': 0.27; 'actual': 0.28; 'referencing': 0.29; 'objects': 0.29; 'connection': 0.30; 'foo': 0.33; 'message-id:@gmail.com': 0.34; 'but': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'mean': 0.38; 'subject:the': 0.39; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'still': 0.40; 'some': 0.40; 'your': 0.60; "you'll": 0.61; 'hope': 0.61; 'charset:windows-1252': 0.62; 'picture.': 0.84; 'please)': 0.84; 'subject:value': 0.84; 'do:': 0.91 X-Virus-Scanned: amavisd-new at torriefamily.org Date: Thu, 27 Aug 2015 12:49:36 -0600 From: Michael Torrie User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: How to reassign the value of the variable on runtime? References: <002e01d0e0f5$d17b4330$7471c990$@gmail.com> In-Reply-To: <002e01d0e0f5$d17b4330$7471c990$@gmail.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1440701388 news.xs4all.nl 23783 [2001:888:2000:d::a6]:60838 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 3750 X-Received-Body-CRC: 519087659 Xref: csiph.com comp.lang.python:95706 On 08/27/2015 12:25 PM, Ivan Evstegneev wrote: > Can some please (I mean very please) explain me how do I reassign > "engine_object" and "meta_object" variables, > so they would store(point to) a new connection objects of my database, > while other functions still would see those variables as their defaults? If I understand you, the solution is fairly simple. Forgive me for not referencing your actual code. But I think you'll get the picture. Simply don't do: from foo import * or even from foo import bar When you do the wildcard import, this puts references to all the objects in foo (or just foo.bar) into your current module's namespace. If you reassign these names, it just rebinds the name in your current module space, not in the imported module's namespace. So the solution is this: import foo foo.bar = "something" Now in every module that imports foo, foo.bar picks up the change because the rebinding happens inside that module's namespace. Hope this makes sense.