Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'attribute': 0.05; 'diff': 0.05; 'modified': 0.05; 'modify': 0.05; '(it': 0.09; 'non-string': 0.09; 'setattr,': 0.09; 'subclass': 0.09; "wouldn't": 0.11; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hmm.': 0.16; 'overriding': 0.16; 'properties,': 0.16; 'subclassing': 0.16; 'subject:object': 0.16; 'subject:when': 0.16; 'using,': 0.16; 'utc,': 0.16; 'wrote:': 0.17; 'certainly': 0.17; 'thu,': 0.17; 'trying': 0.21; 'explicit': 0.22; 'object.': 0.22; 'wednesday,': 0.22; "i'd": 0.22; 'references': 0.23; 'properties': 0.24; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'guess': 0.27; 'possibly': 0.27; 'message-id:@mail.gmail.com': 0.27; 'chris': 0.28; 'comparison': 0.29; 'gather': 0.29; 'though.': 0.29; 'types.': 0.29; 'objects': 0.29; 'probably': 0.29; 'that.': 0.30; 'function': 0.30; 'could': 0.32; 'done,': 0.33; 'to:addr:python- list': 0.33; 'operations': 0.33; 'changed': 0.34; 'received:google.com': 0.34; 'ben': 0.35; 'received:209.85.220': 0.35; 'too.': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'list.': 0.35; 'but': 0.36; 'expensive': 0.36; 'too': 0.36; 'rather': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'mark': 0.38; 'perform': 0.38; 'store': 0.38; 'object': 0.38; 'skip:l 20': 0.38; 'sure': 0.38; 'several': 0.39; 'performance': 0.39; 'to:addr:python.org': 0.39; 'help': 0.40; 'end': 0.40; 'your': 0.60; 'perfect': 0.63; 'burden': 0.65; 'differences': 0.65; 'special': 0.73; 'goal': 0.74; '2013': 0.84; 'effectively,': 0.84; 'having,': 0.84; "it'd": 0.84; 'snapshot': 0.84; 'snapshots': 0.84; 'subject:its': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type:content-transfer-encoding; bh=bUMW6wAILQZlPl9unX7I13DpQJr5okOyjbmUcLeWycY=; b=BdE+q9meFaeRSsOiinrAP7mfOXeVI4+d5lGiH6v1eztxPfhF1t3M/bNjW1dnEz0R6A BMIwbmTtGsbDKzrxj9WI3T5tGzYw3I89J01AkVfEo+V50HC/UpYlcDFZLzfyZyLMoGVA 4jjDVgHkj8DcTWjy2+zsqWrHO7UlaMEoD1bB11IHO0uEUIThvlELGKSRanRZpqrch40e M2KUon5kkkmYXuVum586iOf99vGOaODYrn4uOSWX/oTFaaqxWzUT8TwRn/hXNohDLgcW QOTfwpQxn+r7tXNRIB5suGEXD7gyKbXyzL9BzDZuZOPEK8XrOXcKuyEQJiJfxb0s4GBT KWjg== MIME-Version: 1.0 X-Received: by 10.58.12.200 with SMTP id a8mr11809953vec.52.1362589440014; Wed, 06 Mar 2013 09:04:00 -0800 (PST) In-Reply-To: <5c776c70-aa7d-4b2e-ad7b-54392793c607@googlegroups.com> References: <5c776c70-aa7d-4b2e-ad7b-54392793c607@googlegroups.com> Date: Thu, 7 Mar 2013 04:03:59 +1100 Subject: Re: Creating an object that can track when its attributes are modified From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1362589448 news.xs4all.nl 6939 [2001:888:2000:d::a6]:35631 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:40651 On Thu, Mar 7, 2013 at 3:56 AM, Ben Sizer wrote: > On Wednesday, 6 March 2013 16:22:56 UTC, Chris Angelico wrote: >> >> Effectively, you would need to have a >> subclass of list/dict/tuple/whatever that can respond to the change. > > This is certainly something I'd be interested in having, but I guess that= would be fragile since the user would have the burden of having to remembe= r to use those types. Since you're already overriding setattr, you could simply force all non-string sequences to your special subclass of list. That reduces that burden, though it'd break if there are any other references to the object. >> What's the goal of this class? Can you achieve the same thing by >> using, perhaps, a before-and-after snapshot of a JSON-encoded form of >> the object? >> > > I need to be able to perform complex operations on the object that may mo= dify several properties, and then gather the properties at the end as an ef= ficient way to see what has changed and to store those changes. Any compari= son of before-and-after snapshots could work in theory, but in practice it = could be expensive to produce the snapshots on larger objects and probably = expensive to calculate the differences that way too. Performance is importa= nt so I would probably just go for an explicit function call to mark an att= ribute as having been modified rather than trying to do a diff like that. (= It wouldn't work for rollbacks, but I can accept that.) Hmm. Interesting. The perfect solution probably is too messy, yeah. But if you have your subclassing done, you could possibly snapshot-on-write, which would allow the rollback. Not sure if it'd help though. ChrisA