语法while循环后print语句出错

时间:2017-12-01 05:11:03

标签: python raspberry-pi3

我在我的Raspberry Pi 3中使用Python 2.7并在此print语句中出错:

"%%"

以下是该计划的代码段:

print rc_time(pin_to_circuit)

这是错误:

GPIO.setmode(GPIO.BOARD)

pin_to_circuit=7

def rc_time (pin_to_circuit):
 count=0
 GPIO.setup(pin_to_circuit, GPIO.OUT)
 #some code 
 return count


try:
  while True:
         print rc_time(pin_to_circuit)
except KeyboardInterrupt:
  pass
finally:
  GPIO.cleanup()

def main():
 print 'starting...'
 ldrData= rc_time(pin_to_circuit)
 tPayload= "field1=" % ldrData

 while True:
  try:
   publish.single(topic, payload=tPayload, hostname=mqttHost, port=tPort, 
    tls=tTLS, transport= tTransport)

  except KeyboardInterrupt:
        break
  except:      
        print: 'Error publishing the data'


#call main
if __name__=='__main__':
 main()

1 个答案:

答案 0 :(得分:2)

看起来这种情况发生的唯一方法(如果你真的在Python 2.7上)就是from __future__ import print_function。要解决此问题,请删除该行或将print用作函数。

evidence