Python how to reference variable
<p>I'm getting a problem when referencing variables on a python file. Here is the code:</p>

<pre><code>FG_E = 9
FG_R = 8
START = 7
READY = 9
MC = 3
BRAKE = 5
ERROR = 6
a = 2
b = 3

position = 0

def build_message(signal):
    message = position
    message = message | (0b1&lt;&lt;signal)
    s = bin(message)
    s = s[2:len(s)]
    s = (16-len(s))*'0' + s

    s0 = s[0:len(s)/2]
    s1 = s[len(s)/2:len(s)]
    s0 = s0[::-1]
    s1 = s1[::-1]
    s_final = int(s0 + s1, 2)
    position = s_final
    print bin(s_final)
    return s_final

build_message(FG_R)
</code></pre>

<p>The error I get is:
UnboundLocalError: local variable 'position' referenced berofe assigment</p>

<p>If you are using an outside variable into a function maybe you should consider passing it as an argument, like:</p>

<pre><code>def build_message(signal,position):
    pass
</code></pre>

python