获取“TypeError:必须是字符串,而不是函数”

2024-05-23 15:38:35 发布

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

我用微控制器根据用户输入时间控制灯泡,我在线程中运行这个函数。我一直在time.sleep(1)行得到一个错误:

TypeError: must be a string, not function

def light():
    while True:
        if(hour < 7 or hour > 18):
            digitalWrite(light, LOW)
        elif(hour > 6 and hour < 19):
            digitalWrite(light, HIGH)
        time.sleep(1)
        increment_second()
        print second

#Time increments
def increment_minute():
  global minute
  minute = minute + 1
  if(minute == 60):
    minute = 0;
    increment_hour()

def increment_hour():
  global hour
  hour = hour + 1
  if(hour == 24):
    hour = 0

def increment_second():
  global second
  second = second + 1
  if(second == 60):
    second = 0
    increment_minute()

这是我的回溯:

^{pr2}$

Tags: 用户iftimedef时间sleepgloballight