ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
Re: Question about creating dictionary like objects
by Chris Rebert other posts by this author
Nov 6 2009 2:58PM messages near this date
Question about creating dictionary like objects | regexp question
On Fri, Nov 6, 2009 at 2:06 PM, bowman.joseph@[...].com
<bowman.joseph@[...].com>  wrote:
>  I'm working on a memcached based session library, and I've run into an
>  interesting problem.
> 
>  Here's the full code for the session library - http://pastebin.com/m295fdfc2
> 
>  What I'm doing is using __setitem__ to set an element as a list. When
>  I call .append() on that list, it appears to be modifying the list in
>  memory, but not running __setitem__ on the parent in order for the
>  information to get saved in memcached.

list.append() just appends the item to the list object. That's all it
does *and nothing else*.

It doesn't call __setitem__ on the "parent" object containing the
list; how would it even know about that object to begin with?
(pointers aren't reversible)
With normal containers, there's no need to store modified, mutable
items back in the container: the item got modified in-place, the
reference to it from the container is still valid, so storing it back
would be pointless (sounds like memcached is quirky (but probably
justifiably so) in not having this work).
Perhaps you thought some copying occurs when getting items out of
containers? That's not the case.

Since it sounds like you need to force a __setitem__ call on `session`
to have memcached update its storage, you'll have to do it explicitly.

Change:
session["test"].append(datetime.datetime.now())

To:
#use some name better than "foo" obviously
foo = session["test"] #fetch
foo.append(datetime.datetime.now()) #mutate
session["test"] = foo #store back explicitly so memcached knows there
was a change

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list
Thread:
Bowman.Joseph@Gmail.Com
Chris Rebert

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved