is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ?

r0g aioe.org at technicalbloke.com
Mon Nov 15 05:09:31 EST 2010


On 12/11/10 01:25, Roy Smith wrote:
> In article<ibhi4h$evv$1 at speranza.aioe.org>,
>   r0g<aioe.org at technicalbloke.com>  wrote:
>
>> On 11/11/10 14:22, Stef Mientki wrote:
>>> I can't find how th get to PHP's equivalent of $_Post and $_Cookie ?
>
> PHP is mostly a one-trick pony.  It's meant to be run as a web scripting
> language with Apache (or, I suppose, something else) on the front end.
> As a result, a lot of web-specific things like $_Post and $_Cookie are
> built into the language.
>
> Python is intended to be more general purpose, so things which are built
> in to other languages usually can be found in library modules.  In this
> case, you probably want to look at the SimpleHTTPServer module.
>


Actually when they say "Simple" they really mean it. The the 
SimpleHTTPServer module doesn't parse form data at all. It's pretty easy 
to get that using the urlparse module though...


def do_GET(self):
     getvars = urlparse.parse_qs( self.path )
     field1 = getvars[ "username" ][0]
     field2 = getvars[ "password" ][0]
     if authenticate( field1, filed2 ):
         self.send_response(200)
         self.send_header("Content-type", "text/html")
         self.end_headers()
         self.wfile.write( "welcome" )
     else:
         self.send_response(404)
         self.end_headers()
     return

This may be lower level than you want really and does involve 
permanently running a daemon on your server as opposed to the PHP way of 
doing things (having Apache interpret PHP on a page by page basis).



> My latest gig, however, has had me doing PHP for the past 3 months or
> so.

That's terrible, you have my fullest sympathy in these difficult times.


Roger



More information about the Python-list mailing list