我的python3代码抛出一个Type:Error,我该如何修复它?

我的python3代码抛出一个Type:Error,我该如何修复它?,python,raspberry-pi,Python,Raspberry Pi,我正在使用SenseHat制作树莓圆周率。使用get_temperature在一个长浮点中吐出温度,我一直在尝试更改它,但我只是得到一个类型错误 from sense_hat import SenseHat sense = SenseHat () import time red = [225, 0, 0] green = [0, 225, 0] blue = [0, 0, 225] while 1 == 1: time.sleep(10) rawTemp = sense.

我正在使用SenseHat制作树莓圆周率。使用
get_temperature
在一个长浮点中吐出温度,我一直在尝试更改它,但我只是得到一个类型错误

from sense_hat import SenseHat
sense = SenseHat ()

import time

red = [225, 0, 0]
green = [0, 225, 0]
blue = [0, 0, 225]

while 1 == 1:
    time.sleep(10)

    rawTemp = sense.get_temperature()
    temp = int(rawTemp * 1.8 + 22)

    if temp <= 70:
        tempColor = blue
    elif temp >= 74:
        tempColor = red
    else:
        tempColor = green

    sense.show_message(temp, text_colour = tempColor)
从sense\u hat导入SenseHat
sense=SenseHat()
导入时间
红色=[225,0,0]
绿色=[0,225,0]
蓝色=[0,0,225]
而1==1:
时间。睡眠(10)
rawTemp=传感。获取温度()
温度=int(原始温度*1.8+22)
如果温度=74:
tempColor=红色
其他:
tempColor=绿色
显示消息(临时、文本颜色=临时颜色)

这是我处理的错误代码

Traceback (most recent call last):
  File "/home/pi/Desktop/Python Projects/tempertureReader.py", line 29, in <module>
    sense.show_message(temp, text_colour = tempColor)
  File "/usr/lib/python3/dist-packages/sense_hat/sense_hat.py", line 450, in show_message
    for s in text_string:
TypeError: 'int' object is not iterable
回溯(最近一次呼叫最后一次):
文件“/home/pi/Desktop/Python Projects/temperurereader.py”,第29行,在
显示消息(临时、文本颜色=临时颜色)
文件“/usr/lib/python3/dist packages/sense\u hat/sense\u hat.py”,第450行,在show\u消息中
对于文本字符串中的s:
TypeError:“int”对象不可编辑

好吧,它是在向str索要

sense.show_message(temp, text_colour = tempColor)
如果要在temp中使用int函数,请尝试以下操作:

sense.show_message(str(temp), text_colour = tempColor)

它说的是这样的,您正试图传递
int
在您应该传递
字符串的位置,我是
意思。show_message()