私は2つのファイルを持っています -
foo1.py -
a = 0;
b = {};
def f():
global a;
print "foo1: start a -",a;
a = 10;
print "foo1 changed a to :",a;
global b;
print "foo1: start b - ",b;
b['me'] = 'fool';
print "foo1 changed b to :",b;
foo2.py -
from foo1 import *
print "foo2 a before f:", a
print "foo2 b before f:", b
f();
print "foo2 a after f:",a
print "foo2 b after f:",b
python foo2.py を実行すると、次のように表示されます -
foo2 a before f: 0
foo2 b before f: {} <br/>
foo1: start a - 0
foo1 changed a to : 10
foo1: start b - {}
foo1 changed b to : {'me': 'fool'}
foo2 a after f: 0 // **Doesn't change**
foo2 b after f: {'me': 'fool'} // **Changes**
誰かがこれを説明してもらえますか?