Python shlex Module
Example
Split a shell command into tokens:
import shlex
command = 'python script.py --name "Linus Refsnes" --age 30'
tokens = shlex.split(command)
print(tokens)
Try it Yourself »
Definition and Usage
The shlex module provides utilities for parsing shell-like syntaxes and splitting strings into tokens.
Use it to parse command-line strings, configuration files, or any text that uses shell-like quoting and escaping rules.
Members
Member | Description |
---|---|
join() | Concatenate tokens into a shell-escaped string. |
quote() | Return a shell-escaped version of a string. |
shlex | Class for parsing shell-like syntaxes. |
split() | Split a string using shell-like syntax. |