我在我的树莓皮皮上使用python 3.10.5,我正在尝试使用
match
&
case
而不是
if
语句当我尝试运行程序时,它会返回一个错误:
Traceback (most recent call last):
File "<stdin>", line 22
SyntaxError: invalid syntax
以下是我的功能:
async def BlueTooth(delay):
while True:
if uart.any():
command = uart.readline()
#print(command) # uncomment this line to see the received data
match command:
case b'1':
led.value(1)
case b'0':
led.value(0)
write_i2c("cmd: {}\n{}".format(command, Commands.get_command_action(str(command))))
await asyncio.sleep(delay)
我已经检查过了,一切都应该正常,是什么原因导致了问题?
顺便说一句,我正在使用
Thonny
作为我的编辑。