How to detect if script ran from Django or command prompt?
<p>I have a Python script that pauses for user input (using <code>raw_input</code>, recently I created a Django web UI for this script. Now when I execute the script via Django is pauses as it's waiting for input in the backend. </p>

<p>How can I determine if the script was ran from Django or terminal/cmd/etc? I don't want to maintain 2 streams of code, one for web and another one for terminal.</p>

<p>Just ask!</p>

<pre><code>&gt;&gt;&gt; import os
&gt;&gt;&gt; import sys
&gt;&gt;&gt; os.isatty(sys.stdin.fileno())
True
</code></pre>

<p>if true, you are attached to a console.</p>

python django