Python/ASP Docs/Questions
Graham Breed
graham at nospam.microtonal.co.uk
Thu Feb 15 15:16:00 EST 2001
In article <3A8A0A3E.A1EF40E9 at bigfoot.com>, rogersd at bigfoot.com (Dave
Rogers) wrote:
> 2) I want to set cookies easily using Response. I would like to go
> Response.Cookies('name') = 'bob' (for a simple cookie), but instead I
> am forced to go
>
> import Cookie
> c = Cookie.Cookie()
> ...
> Response.AddHeader("Set-Cookie", c[12:])
> (or something similar to that)
Here's an example that sets a cookie iff it isn't already set.
cookieName = 'example cookie'
cookie = str(Request.Cookies(cookieName))
# needs to be converted to a string to evaluate as false
if not cookie:
Response.Cookies[cookieName]='cookie read'
c = Response.Cookies(cookieName)
c.expires = pywintypes.Time(time.time()+600)
> I know Cookies is a collection - I seem to have this problem setting
> ASP Object values in general as I have to go Session.SetValue to set
> session variables.
Yes, it's because Python doesn't allow you to assign to the result of a
function.
Not that it's a problem with session variables, because they're evil
anyway.
Graham
More information about the Python-list
mailing list