Loading a Cookie from a Dictionary

John J. Lee jjl at pobox.com
Fri Feb 6 19:47:55 EST 2004


"Michael Sampson" <samp0082_at_umn_dot_edu> writes:

> "John J. Lee" <jjl at pobox.com> wrote in message
> news:87wu76ic6x.fsf at pobox.com...
[...]
> Assume I have a server trying to create a cookie to send to the browser.
> Instead of making the cookies one at a time like
> 
> c = Cookie.Cookie()

You probably want Cookie.SimpleCookie instead.


> c['firstname'] = 'joe'
> 
> c['lastname'] = 'samson'
> 
> c['lastname'][max-age] = 3600
> 
> I want to be able to store the info for the cookies in one dictonary and
> pass that to the constructor for Cookie(), or load it into the cookie using
> c.load().

There's no method to call to do that, AFAIK.  Just write a function
that does exactly what you write above (only getting the keys and
values from the dict, of course: you want a "name" and "value" key as
well as "max-age", etc., I guess, with values in this case "lastname"
and "samson").


John



More information about the Python-list mailing list