[melbourne-pug] python question

Anthony Briggs anthony.briggs at gmail.com
Tue Apr 3 07:21:14 CEST 2012


Stepping through this in a debugger (eg. Winpdb) might help you follow the
chain of cause and effect.

Anthony

On 3 April 2012 12:05, Brian May <brian at microcomaustralia.com.au> wrote:

> Hello,
>
> The following code:
>
> === a ===
> import b
> import c
> b.init()
> print b.value
> c.action()
> === end ===
>
> === b.py ===
> value = None
> def init():
>    global value
>    value = "something"
> === end ===
>
> === c.py ===
> from b import value
> import b
>
> def action():
>    print value
>    print b.value
> === end ===
>
> generates the following output:
>
> === output ===
> something
> None
> something
> === end ===
>
> Question: Why is the second line None, and not something? Then, why is
> the third line something?
>
> This is kind of confusing me.
>
> I suspect it might be some sort of misunderstanding I have with
> Python. However I can't think of what that might be. I would have
> though "from b import value" and "import b" should give the same
> results.
>
> If I swap the order of "import c" and "b.init()" in a, then all the
> results are something.
>
> If I change the value in the line "value = None", then I get that
> value instead of None on the 2nd line - is like I have two copies of
> b.value.
>
> Thanks
> --
> Brian May <brian at microcomaustralia.com.au>
> _______________________________________________
> melbourne-pug mailing list
> melbourne-pug at python.org
> http://mail.python.org/mailman/listinfo/melbourne-pug
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/melbourne-pug/attachments/20120403/fdfc58e3/attachment.html>


More information about the melbourne-pug mailing list