shlex.shlex()
shlex.shlex() is a Python function in the Shlex Module category. Creates a lexical analyzer for shell-like syntax. The syntax is shlex.shlex(instream=None, infile=None, posix=True, punctuation_chars=False). Returns: Shlex object. A typical example: lexer = shlex.shlex("echo hello", posix=True)
list(lexer) # ["echo", "hello"]. A close sibling is shlex.split(), which splits a shell-like string into tokens, respecting quotes. A close sibling is shlex.join(), which joins tokens into a shell-safe command string. More about this category: Shell lexical analyzer — shlex, split, join. Related Shlex Module entries: shlex.split(), shlex.join(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details. You can try shlex.shlex() immediately in the Python playground, look up unfamiliar terms in the glossary, or return to the Python Reference homepage.