shut up in python

To shut up in Python, you can redirect the standard output and error streams to a null device using the subprocess module and os.devnull constant.

main.py
import subprocess
import os

# command to run
cmd = "some_command"

# redirect stdout and stderr to /dev/null
with open(os.devnull, 'w') as devnull:
    subprocess.call(cmd, stdout=devnull, stderr=devnull)
206 chars
10 lines

This will run some_command without printing any output to the console. The with statement opens /dev/null as a file object with write permissions, and passes it as the stdout and stderr arguments to subprocess.call(), which will redirect the output of the command to the null device.

gistlibby LogSnag