Python-Perl Translation

Max M maxm at mxm.dk
Tue Jan 29 04:19:49 EST 2002


Ben Ocean wrote:

> #!/usr/bin/perl
> ($user_id,$banner_id,$page) = split(/&/,$ENV{QUERY_STRING});
> $redirect = 
> "http://www.myaffiliateprogram.com/u/$user_id/t.asp?id=$banner_id&p=$page";
> print "Location: $redirect\n\n";
> exit;
> 
> I have this, but as you can see, I don't know what to substitute for 
> $ENV{QUERY_STRING}:
> 
> import string
> import urllib
> 
> x = string.split("$ENV{QUERY_STRING}","&")
> user_id = x[0]
> banner_id = x[1]
> page = x[2]
> urlopen(http://www.myaffiliateprogram.com/u/$user_id/t.asp?id=$banner_id&p=$page) 
> 
> 
> What do I do on the $ENV thing and how does the rest of the code look?
> TIA,
> BenO

Why not just use the cgi module? No nee to parse the querystring yourself.

from cgi import FieldStorage

query = FieldStorage()
user_id   = query['user_id']
banner_id = query['banner_id']
page      = query['page']

etc. ...

regards Max M




More information about the Python-list mailing list