thnx guys.

On 24.01.2014 01:10, Terry Reedy wrote:
  Johannes Schneider <johannes.schnei...@galileo-press.de> Wrote in
  message:
On 22.01.2014 20:18, Ned Batchelder wrote:
On 1/22/14 11:37 AM, Asaf Las wrote:
Chris is right here, too: modules are themselves singletons, no matter
how many times you import them, they are only executed once, and the
same module object is provided for each import.

I'm not sure, if this is the whole truth.

think about this example:

cat bla.py
a = 10

cat foo.py
from bla import a

This makes a a global in foo, bound to 10

def stuff():
          return a

This a refers to the global a in foo.

cat bar.py
from foo import stuff
print stuff()
a = 5

This bar.a is irrelevant to the behavior of stuff.

print stuff()

from bla import *
print a

python bar.py
10

foo.a == 10

10

foo.a == 10

10

bla.a == 10

here the a is coming from bla

Twice

and is known in the global namespace.

There is no global namespace outside of modules.

the value differs in stuff()

No it does not.

and before/after the import statement.

foo.a does not change. bar.a is never used.

So the instance of the module differs

Nope. Each of the three module instances is constant. The bindings
within each could change, but there are no rebinding in the code above.



--
Johannes Schneider
Webentwicklung
johannes.schnei...@galileo-press.de
Tel.: +49.228.42150.xxx

Galileo Press GmbH
Rheinwerkallee 4 - 53227 Bonn - Germany
Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax)
http://www.galileo-press.de/

Geschäftsführer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker
HRB 8363 Amtsgericht Bonn
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to