Python中使用keyword内置模块来获取当前Python版本的所有关键字的列表,并且执行keyword.kwlist列表中的__peg_parser__关键字时,报错:SyntaxError: You found it!。本文主要简单介绍一下__peg_parser__。

1、PEG 语法解释器

文档https://www.python.org/dev/peps/pep-0617/

2、__peg_parser__所在Python版本

PEG 语法解释器将在Python 3.10中删除。另外,它在早期的Python版本中不存在。

Python 2.7:

>>> __peg_parser__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name '__peg_parser__' is not defined

Python 3.6:

>>> __peg_parser__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name '__peg_parser__' is not defined

Python 3.9:

>>> __peg_parser__
  File "<stdin>", line 1
    __peg_parser__
    ^
SyntaxError: You found it!

Python 3.10:

>>> __peg_parser__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name '__peg_parser__' is not defined