imported var not being updated

Benjamin Kaplan benjamin.kaplan at case.edu
Tue Mar 9 09:25:38 EST 2010


On Tue, Mar 9, 2010 at 9:18 AM, John Posner <jjposner at optimum.net> wrote:
> On 3/8/2010 11:55 PM, Gary Herron wrote:
> <snip>
>>>> The form of import you are using
>> from helpers import mostRecent
>> makes a *new* binding to the value in the module that's doing the
>> import.
>>>> <snip>
>>> What you can do, is not make a separate binding, but reach into the
>> helpers module to get the value there. Like this:
>>>> import helpers
>> print helpers.mostRecent
>>>>> Gary, are you asserting that in these separate situations:
>> one.py:
>> from helpers import mostRecent
> x = mostRecent
>> two.py:
>> import helpers
> x = helpers.mostRecent
>>> ... the name "x" will be bound to different objects?
>> Tx,
> John
>>No. the name x will be bound to the same object. It's the other way that
gives a problem
from helpers import mostRecent
works like
import helpers
mostRecent = helpers.mostRecent
del helpers
so when you do
mostRecent = x
it rebinds "mostRecent" in the current scope but doesn't affect
helpers.mostRecent, the name in the "helpers" module.
> --
> http://mail.python.org/mailman/listinfo/python-list
>-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100309/eeb0e311/attachment-0001.html>


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /