[mod_python] global

Nick nick at dd.revealed.net
Tue Oct 4 13:58:50 EDT 2005


And just to be clear, this would also behave similarly for lists, dicts and 
other objects if you actually change the assignment to a different object, 
although in those cases you could alter the object and still see the changes 
in your local scope.

Nick

Nick wrote:
> In Python assignments to numbers and strings make copies, which is what 
> is happening in a "from test1 import *" statement.  The G1 in your 
> global scope is a copy of the G1 in the module's global scope, which 
> turn out to be different variables.  You'll have to "import test1" and 
> refer to test1.G1.
> 
> Nick
> 
> Paul Hide wrote:
> 
>> file test1.py contains:
>> def sub1():
>>     global G1
>>     print 'sub1'
>>     G1 = 43
>>
>> If I enter the following code in Idle I (naively) expect G1 to have a 
>> value:
>> from test1 import *
>> global G1
>> sub1()
>> print G1
>>
>> but it does not.
>> Could someone clarify?
>>
>> Many thanks for an interesting mailing list.
>>
>> Paul Hide
>>
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Mod_python mailing list
>> Mod_python at modpython.org
>> http://mailman.modpython.org/mailman/listinfo/mod_python
> 
> 
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python



More information about the Mod_python mailing list