import from question

George Sakkis george.sakkis at gmail.com
Tue Jan 15 00:25:14 CET 2008


On Jan 14, 4:22 pm, iu2 <isra... at elbit.co.il> 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



More information about the Python-list mailing list