the global keyword:

BartC bc at freeuk.com
Sun Jun 12 17:10:30 EDT 2016


On 12/06/2016 20:25, Ned Batchelder wrote:
> On Sunday, June 12, 2016 at 3:08:01 PM UTC-4, BartC wrote:
>> On 12/06/2016 00:44, Marcin Rak wrote:

>>> from Test import some_function, my_print
>>> from Test import test_var
>>>
>>> some_function()
>>> my_print()
>>> print(test_var)
>>> *****************************************
>>>
>>> and I have the following Test.py:
>>> *****************************************
>>> test_var = 5

>>   from Test import a,b,c
>>
>> is equivalent to:
>>
>>   import Test
>>
>>   a = Test.a
>>   b = Test.b
>>   c = Test.c
>>
>> which I hadn't been aware of. Then the link between a and Test.a (eg.
>> Test.test_var) is broken (unless Test.a is something like a list so both
>> still refer to the same data. But assignment to either - not an in-place
>> mod - will break the connection).
>
> Just to clarify: there is no link directly between a and Test.a, except that
> both refer to the same object.

OK, but I meant the link there have been if 'a' was in fact a synonym 
for Test.a.

   Just as here there is no link between x
> and y:
>
>     x = 12
>     y = x

(And that's a good illustration of why 'y' isn't a name reference to 
'x', referring to the "...ducks limp" thread. But best not to rake it up 
again...)

-- 
bartc



More information about the Python-list mailing list