[Tutor] I sure do love cookies.

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Mon Jul 4 10:11:28 CEST 2005



On Fri, 1 Jul 2005, D. Hartley wrote:

> Anyone have a good (*simple*) tutorial on making/sending cookies via
> python? (i.e., not receiving/messing with them).

Hi Denise,

I did find one tutorial here that might help with the receiving side of
things:

    http://www.voidspace.org.uk/python/articles/cookielib.shtml

To make cookies, in the examples of the Cookie module will probably help
the most:

    http://www.python.org/doc/lib/cookie-example.html

>From the documentation, it sounds like Cookie.SimpleCookie is what you're
looking for:

######
>>> import Cookie
>>> mycookie = Cookie.SimpleCookie()
>>> mycookie['pop'] = 'tart'
>>>
>>> mycookie
<SimpleCookie: pop='tart'>
>>>
>>> print mycookie
Set-Cookie: pop=tart;
######

as the page at the very beginning of the Cookie documentation says that
Cookie.SmartCookie is too smart and trusting for its own good.


Best of wishes!



More information about the Tutor mailing list