title: Distinguish from command line and CGI in python
body: <p>is it possible to distinguish whether my Python script is being executed from the web server (as CGI script) or from the command line?</p>
  
  <p>I've seen some replies only for PHP and Perl:<br>
  <a href="https://stackoverflow.com/questions/173851/what-is-the-canonical-way-to-determine-commandline-vs-http-execution-of-a-php-s">What is the canonical way to determine commandline vs. http execution of a PHP script?</a><br>
  <a href="https://stackoverflow.com/questions/1914966/how-can-i-determine-if-a-script-was-called-from-the-command-line-or-as-a-cgi-scr">How can I determine if a script was called from the command line or as a cgi script?</a></p>