How to tell whetehr Python script called as CGI or from command line?

rowan at sylvester-bradley.org rowan at sylvester-bradley.org
Fri May 11 08:13:46 EDT 2007


> import os
> if "QUERY_STRING" in os.environ:
>      # CGI script
>
> might work.

Thanks Steve for this suggestion. I did something similar:
    import os
    req = os.getenv('REQUEST_URI')
    if (not req is None) and len(req) > 0:
        web = True

which seemed to work for me.

Rowan




More information about the Python-list mailing list