Q:

How I solve this TypeError in python?

I am working in python based on a Java code.
I have this in Java:
public static byte[]  datosOEM = new byte[900000]; 

I wrote this in Python following some documents that I found:
datosOEM=bytes([0x90, 0x00, 0x00])

When I run my program it shows me this:
Traceback (most recent call last):
  File "test.py", line 63, in <module> # The line 63 is the location of x1=datosOEM[k];
    x1=datosOEM[k];
IndexError:string index out of range

Craig correct this part and recommended me to change to this:
datosOEM = bytearray(900000)

Now, when I run my program it shows me this:
Traceback (most recent call last):
  File "test.py", line 10, in <module> # The line 10 is the location of datosOEM = bytearray(900000)
    datosOEM = bytearray(900000)
TypeError: 'type' object has no attribute '__getitem_'

How I can fix this problem?
Part of my code is this:
...
response=port.read(8)
print(response)
k=0
C=0
conexion=True
if(conexion):
    while(response>200):
        while(C==0):
            x1=datosOEM[k];
            if(x1=1):
                x2=datosOEM[k+1];
... 

A:

Craig certainly told you how to create a bytearray with 900000 bytes:
datosOEM = bytearray(5)
print(datosOEM)          # bytearray(b'\x00\x00\x00\x00\x00')
datosOEM[0] = 65
print(datosOEM)          # bytearray(b'A\x00\x00\x00\x00')

