[Tutor] Cookielib - CookieJar objects

Kent Johnson kent37 at tds.net
Wed Jun 29 12:22:53 CEST 2005

Danny Yoo wrote:
> Yes, whenever the documentation talks about something being "iterable",
> they really mean that we can use a for loop across it.  It does seem a
> little odd that this appears to be a primary way to access the cookies in
> a cookie jar:
>     http://www.python.org/doc/lib/node534.html
> I wonder why; I haven't been able to figure out a good reason for this
> kind of interface.  Are cookie jars files known to be large?

I was perplexed by this too when I did the challenge Denise is on. Your question prompted a look at the cookielib source. It turns out that iterating over the CookieJar is actually doing a recursive tree walk of the contents of the CookieJar.

This only pushes the mystery one step back, though - the attribute of the Cookie that is recursively iterated is called 'item', but the Cookie class defined in cookielib has no attribute 'item'.

Take a look at cookielib.deepvalues() if you are curious.


More information about the Tutor mailing list