11Mar(Confusing) Python Package Variables

package A: a = 10

package B: import A A.a = 12

package C: from A import a def f(): print a

package D: import A import C import A

C.f()

prints 10

Why?

Because in package B: A.a is referenced to another new object while in package C, global a still refers to the old object.

I think it’s better to think of python variable name as a pointer.


March 2008
M T W T F S S
 12
3456789
10111213141516
17181920212223
24252627282930
31