[Tutor] environment data

Sean 'Shaleh' Perry shalehperry@attbi.com
Fri, 28 Dec 2001 18:50:35 -0800 (PST)


On 29-Dec-2001 Kirk Bailey wrote:
> ok, I want to read a environment variable in a script. 
> This contains 'everything after the first "?" in the url' according to
> my reading.
> My application will have 1 word there.
> The url is
> http://www.howlermonkey.net/cgi-bin/commander.py?(listname)
> where (listname) is replaced by a 1 word string, the name of the list of
> intrest.
> 
> cgi module leaves me baffled, but if I can just read the bloddy
> environment variable I can run with it from there.
> 

import os.environ

print os.environ['MY_DATA']

The cgi module for python passes os.environ as a parameter:

environ = os.environ

environ['REQUEST_METHOD']

cgi.py is a lot like rfc822, it parses headers and other data storing them in a
dictionary and giving you access to them as if the returned item was a
dictionary itself.