On the SaltyCraneBlog (http://www.saltycrane.com/blog/2008/01/python-variable-scope-notes/#c7900), I was reading up on the variable scope in Python and everything was all pretty straightforward, until I got this workaround for setting global variables:
def ex8():
ex8.var = 'foo'
def inner():
ex8.var = 'bar'
print 'inside inner, ex8.var is ', ex8.var
inner()
print 'inside outer function, ex8.var is ', ex8.var
ex8()
What's throwing me off is the ex8.var part. Is this an attribute? If var is an attribute of ex8, wouldn't var need to be defined first? Can a function's attributes be called within the function itself?