python中的索引器

2024-06-01 01:59:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我在基于Java代码的python中工作。你知道吗

我在Java有这样一个例子:

public static byte[]  datosOEM = new byte[900000]; 
public static byte x1=0,x2=0,x3=0,x4=0,x5=0,x6=0;

我用Python编写了以下文档:

datosOEM=bytes([0x90, 0x00, 0x00])
x1=bytes([0x00])
x2=bytes([0x00])
x3=bytes([0x00])
x4=bytes([0x00])
x5=bytes([0x00])
x6=bytes([0x00])

当我运行程序时,它会显示:

Traceback (most recent call last):
  File "test.py", line 63, in <module>
    x1=datosOEM[k];
IndexError:string index out of range

如何解决这个问题?任何帮助都会受到欢迎。你知道吗

我的部分代码是:

...
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];
... 

还有,我该怎么做才能不重蹈覆辙呢?你知道吗

事先谢谢你的帮助

这篇文章是由JasonMArcher编辑的,非常感谢。你知道吗


Tags: 代码bytesresponsestaticjavabytepublicx1
1条回答
网友
1楼 · 发布于 2024-06-01 01:59:37

我不知道你想达到什么目的。也许是这样的?你知道吗

datosOEM = [0]*900000 # a list of length 900.000, initialized with zeros
x1 = 0
x2 = 0
x3 = 0
# ...

也许你想要这个:

datosOEM = [0]*900000 # a list of length 900.000, initialized with zeros
x = [0]*6
# ...
# ...
    while (C==0):
        x[0] = datosOEM[k];
        if (x[0] = 1):
            x[1] = datosOEM[k+1];
        # ...

相关问题 更多 >