→ Antwort auf Is it in this case : http://identi.ca/url/75523035 (see : [01:16] [1]1 — Julien-Claude Fagot, die eine Antwort war auf One more reason why you should not use “from bla import foo”: print __import__(obs.__class__.__module__).__file__ [2] — ArneBab
Datei: bla.py
def foo(): print "bla"
Interaktiver Test:
\>>> import bla \>>> bla.foo() bla \>>> def fu(): ... print "fu" ... \>>> fu() fu \>>> from bla import foo \>>> foo() bla \>>> bla.foo = fu \>>> bla.foo() fu \>>> foo() bla
Profifrage: Was passiert, wenn du from bla import foo
nach bla.foo = fu
ausführst?
Antwort:
\>>> import bla \>>> bla.foo() bla \>>> def fu(): ... print "fu" ... \>>> fu() fu \>>> bla.foo = fu \>>> bla.foo() fu \>>> from bla import foo \>>> foo() fu
Happy hacking!
dsop: if you use 'bla.foo', then yes, you can assign to bla.foo and you'll see the change. If you do 'from bla import foo', then your locally imported 'foo' will not 'see' changes to bla.foo. ↩
Links:
[1] http://identi.ca/notice/100260976
[2] http://identi.ca/notice/100258278