Checking for interactive shell in a Python script

This is often works well enough

import os, sys
if os.isatty(sys.stdout.fileno()):
    ...

Leave a Comment