title: How to tell if python script is being run in a terminal or via GUI?
body: <p>I'm working in Linux and am wondering how to have python tell whether it is being run directly from a terminal or via a GUI (like alt-F2) where output will need to be sent to a window rather than stdout which will appear in a terminal.</p>
  
  <p>In bash, this done by:</p>
  
  <pre><code>if [ -t 0 ] ; then  
      echo "I'm in a terminal"
  else
      zenity --info --title "Hello" --text "I'm being run without a terminal"
  fi
  </code></pre>
  
  <p>How can this be accomplished in python? In other words, the equivalent of [ -t 0 ])?</p>