Py学习  »  Python

micropython-SyntaxError中的匹配大小写:无效语法

David • 1 年前 • 783 次点击  

我在我的树莓皮皮上使用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 作为我的编辑。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/158009
 
783 次点击  
文章 [ 1 ]  |  最新文章 1 年前