while 循环后打印语句的语法错误

Syntax Error with print statement after while loop

我将 Python 2.7 与我的 Raspberry Pi 3 一起使用,并在此打印语句中遇到错误:

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()

这里是错误:

File "ldrmqtt.py", line 65
  print rc_time(pin_to_circuit)
              ^
SyntaxError: invalid syntax

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

evidence