Java 如何在python中解决这个类型错误?

Java 如何在python中解决这个类型错误?,java,python,python-2.7,Java,Python,Python 2.7,我正在使用基于Java代码的python 我有一个Java版本: public static byte[] datosOEM = new byte[900000]; 我使用Python编写了以下文档: datosOEM=bytes([0x90, 0x00, 0x00]) 当我运行程序时,它向我显示: Traceback (most recent call last): File "test.py", line 63, in <module> # The line 63 i

我正在使用基于Java代码的python

我有一个Java版本:

public static byte[]  datosOEM = new byte[900000]; 
我使用Python编写了以下文档:

datosOEM=bytes([0x90, 0x00, 0x00])
当我运行程序时,它向我显示:

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
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_'
现在,当我运行我的程序时,它向我显示:

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
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_'

Craig当然告诉过你如何创建一个900000字节的bytearray:

datosOEM = bytearray(5)
print(datosOEM)          # bytearray(b'\x00\x00\x00\x00\x00')
datosOEM[0] = 65
print(datosOEM)          # bytearray(b'A\x00\x00\x00\x00')

如果(x1=1):
,你的程序甚至不会编译。所有的x都是以这种形式出现在Java上的:公共静态字节x1=0,x2=0,x3=0,x4=0,x5=0,x6=0;我不知道如何将其传递到pythonIsn中,90000不是Java中字节数组的维数吗?datosOEM中存储了什么?那么,您对第一行有什么看法?我认为“public static byte[]datosOEM=new byte[900000];”意味着datosOEM中有900000个字节。关于属性getitem的TypeError发生了什么?我无法重现TypeError。我只是证明了这段代码,代码没有显示任何错误。非常感谢你。另一件事,这是索诺德太多的要求,但,你能帮我一个忙,投票“喜欢”这篇文章,当然我也投票“喜欢”你的答案。请