On Jan 14, 4:22 pm, iu2 <[EMAIL PROTECTED]> wrote:
> Hi all
>
> I've got three files:
>
> file a1.py:
> ========
> the_number = None
>
> file a2.py:
> ========
> import a1
>
> def init():
>     a1.the_number = 100
>
> file a3.py:
> ========
> from a1 import the_number
> import a2
>
> a2.init()
> print the_number, type(the_number)
>
> Runninr a3.py I get:
> None <type 'NoneType'>
>
> Changing a3.py to:
> import a1
> import a2
>
> a2.init()
> print a1.the_number, type(a1.the_number)
>
> gives:
> 100 <type 'int'>
>
> Why doesn't it work in the first version of a3.py?
>
> Thanks,
> iu2

Try to guess what the following snippet prints, run it, and see if you
guessed correctly:

s = {'a':None}
x = s['a']
s['a'] = 1
print x

The same mechanism applies to what "from ... import" does.

HTH,
George
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to