Local, Global and objects in Python
<p>I have a question about local and global variables and global objects in Python. Look at this code:</p>

<pre><code>var = 0

class Test():
    var = 0

test = Test()

def sum():
    Test.var += 1
    test.var += 1
    var += 1

sum()
</code></pre>

<p>If I run that code, the exception is triggered in the line "var += 1" only. The two previous lines work. I read <a href="http://docs.python.org/faq/programming.html#what-are-the-rules-for-local-and-global-variables-in-python" rel="nofollow">this question</a> from the Python FAQ. I think that there is no exception in the first two lines of the function because the "Test"  and "test" are referenced. The member "var" is assigned, but "Test" and "test" are global because are referenced to get the member. The FAQ said: "In Python, variables that are only referenced inside a function are implicitly global. If a variable is assigned a new value anywhere within the function’s body, it’s assumed to be a local."</p>

<p>So, the question is... is my assumption true?</p>
