Python TypeError: 'int' object has no attribute '__getitem__'

Python TypeError: 'int' object has no attribute '__getitem__'

import bluetooth
import time

class btHandler():

    hostMACAddress = '98:D3:31:30:45:80'
    port = 1
    gyro = [None]
    rot = [None]
    data = 0

    def __init__(self):
        self.clientSocket = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
        self.clientSocket.connect((self.hostMACAddress, self.port))
        self.clientSocket.setblocking(True)

    def testRead(self):
        self.gyro = [None] * 3
        global data
        d = self.clientSocket.recv(1)
        d = ord(d[0])
        if d == 0x25:
            d = self.clientSocket.recv(1)
            d = ord(d[0])
            if d == 0x72:
                time.sleep(0.02)
                self.data = self.clientSocket.recv(28)
            if len(self.data)<28:
                print "Wrong data lenght", len(self.data)
            else:
                self.gyro[0] = ord(self.data[0]) * 256 + ord(self.data[1])
                print self.gyro[0]
                return self.gyro[0]

    def getGyroValues(self):
        self.rot = [None] * 3
        self.rot[0] = ord(self.data[10]) * 256 + ord(self.data[11])
        print rot[1];

这是我的代码,我在第 37 行遇到错误 (self.rot[0] = ord(self.data[10]) * 256 + ord(self.data[ 11])) 我的程序所做的是使用蓝牙读取数据微控制器。

__getitem__是索引,所以检查你的代码,看看你的代码中是否对一个int做了索引操作([]),并修复它。