free and open-source Python module for making system calls and interacting with the underlying OS

tags:

There are many Linux commands, some of which are highly evolved for certain tasks. The subprocess module leverages the expressiveness of the command line (flags, wildcards, etc.) by making any Linux command available within Python scripts.

Suppose you're writing a script to operate on all pdf files in the current directory. One option is to list the directory's contents with Python's os.listdir(), check for pdf's, etc. An alternative is to pass subprocess the Linux command ls -t *.pdf, a one-liner that lists all pdf's in the current directory, sorted by modification time. Very convenient!