Py3: Terminal or browser output?
Diez B. Roggisch
deets at nospam.web.de
Sat Feb 13 15:17:15 EST 2010
Am 13.02.10 20:46, schrieb Gnarlodious:
> Hello, searched all over but no success. I want to have a script
> output HTML if run in a browser and plain text if run in a Terminal.
> In Python 2, I just said this:
>
> if len(sys.argv)==True:
>
> and it seemed to work. Py3 must have broken that by sending a list
> with the path to the script in BOTH the browser and Terminal. Is there
> some newfangled way to determine what is running the script (hopefully
> without a try wrapper)?
I have no idea what you mean by "running python in a browser". I can
only guess you mean as cgi or mod_python-skript?
However, maybe
if os.isatty(sys.stdout.fileno()):
works for you.
Or you could check for certain environment variables that are present
when running as CGI or mod_python skript, but not knowing *what* you do
can only lead to educated guesses at best.
Diez
More information about the Python-list
mailing list