is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ?
aioe.org at technicalbloke.com
Mon Nov 15 11:09:31 CET 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...
getvars = urlparse.parse_qs( self.path )
field1 = getvars[ "username" ]
field2 = getvars[ "password" ]
if authenticate( field1, filed2 ):
self.wfile.write( "welcome" )
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
That's terrible, you have my fullest sympathy in these difficult times.
More information about the Python-list