shlex — 简单的词法分析

源代码: Lib/shlex.py


The shlex class makes it easy to write lexical analyzers for simple syntaxes resembling that of the Unix shell. This will often be useful for writing minilanguages, (for example, in run control files for Python applications) or for parsing quoted strings.

The shlex 模块定义了下列函数:

shlex. split ( s , comments = False , posix = True )

Split the string s using shell-like syntax. If comments is False (the default), the parsing of comments in the given string will be disabled (setting the commenters 属性在 shlex instance to the empty string). This function operates in POSIX mode by default, but uses non-POSIX mode if the posix argument is false.

3.12 版改变: 传递 None for s argument now raises an exception, rather than reading sys.stdin .