TypeError: 'int' object does not support item assignment, In threads
<p>I have 2 modules:</p>

<p>First Keyboard.py</p>

<pre><code>import USB,evdev,threading,sys

global codigo
codigo = [1]
class Teclado:
    def __init__(self,port):
        self.puerto = USB.usb(port)
    def iniciar_teclado(self):
        p = threading.Thread(target=self.puerto.obtener_evento,args=(codigo))
        p.start()
        while 1:
            if codigo[0] == evdev.ecodes.KEY_A:
                print('A')
            elif codigo[0] == evdev.ecodes.KEY_B:
                print('B')
</code></pre>

<p>and USB.py:</p>

<pre><code>import evdev,os,signal,sys
class usb:
    def __init__(self,dev):
        self.device = evdev.InputDevice(dev)
        print(self.device)
    def obtener_evento(self,c):
        for event in self.device.read_loop():
            if event.type == evdev.ecodes.EV_KEY and event.value == 1:
                c[0] = event.code
</code></pre>

<p>So to pass by reference a variable in a thread, i use a list of a single element. As help, the following code has been taken as reference:</p>

<pre><code>&gt;&gt;&gt; c = [1]
&gt;&gt;&gt; def f(list):
&gt;&gt;&gt;     list[0] = 'a'
&gt;&gt;&gt; f(c)
&gt;&gt;&gt; c[0]
'a'
</code></pre>

<p>but in my code, in the line</p>

<pre><code>c[0] = event.code
</code></pre>

<p>python tell me </p>

<pre><code>TypeError: 'int' object does not support item assignment
</code></pre>

<p>Some help?</p>

<p>try</p>

<pre><code>p = threading.Thread(target=self.puerto.obtener_evento,args=(codigo,))
</code></pre>

python pass-by-reference python-multithreading input-devices