A basic method only remembers symbols, binding occurs upon invocation.
Python bindings 101
A class can bind variable, and so can an instance (object), and method invocation can change the instance and class variables.
http://ideone.com/KkzhRk
class Binder(object):
x = "x"
y = "y"
z = "z"
def f1(self):
self.x = "xx"
self.y = "yx"
self.z = "zx"
def f2(self):
Binder.x = "xx"
Binder.y = "yx"
Binder.z = "zx"
binder = Binder()
print(Binder.x) # class access
print(Binder.y) # class access
print(Binder.z) # class access
print(binder.x) # instance access
print(binder.y) # instance access
print(binder.z) # instance access
binder.f1()
print(Binder.x) # class access
print(Binder.y) # class access
print(Binder.z) # class access
print(binder.x) # instance access
print(binder.y) # instance access
print(binder.z) # instance access
binder.f2()
print(Binder.x) # class access
print(Binder.y) # class access
print(Binder.z) # class access
print(binder.x) # instance access
print(binder.y) # instance access
print(binder.z) # instance access
There is also the topic of closures – nested method binding the values of the enclosing method.
http://ideone.com/bBnUJG
def mkclosure():
x = "x"
y = "y"
z = "z"
def closure():
# Need to reference them for the closure to be created.
return (x, y, z)
return closure
function = mkclosure()
for cell in function.__closure__:
print(cell.cell_contents)