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


Groups > comp.lang.python > #95706 > unrolled thread

Re: How to reassign the value of the variable on runtime?

Started byMichael Torrie <torriem@gmail.com>
First post2015-08-27 12:49 -0600
Last post2015-08-27 12:49 -0600
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: How to reassign the value of the variable on runtime? Michael Torrie <torriem@gmail.com> - 2015-08-27 12:49 -0600

#95706 — Re: How to reassign the value of the variable on runtime?

FromMichael Torrie <torriem@gmail.com>
Date2015-08-27 12:49 -0600
SubjectRe: How to reassign the value of the variable on runtime?
Message-ID<mailman.86.1440701388.11709.python-list@python.org>
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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web