Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #40643

Re: Creating an object that can track when its attributes are modified

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsreader4.netcologne.de!news.netcologne.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.016
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'append': 0.07; 'attributes': 0.07; "object's": 0.09; 'subclass': 0.09; 'such.': 0.09; 'modification': 0.15; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:object': 0.16; 'subject:when': 0.16; 'using,': 0.16; 'wrote:': 0.17; 'detect': 0.17; 'thu,': 0.17; 'references': 0.23; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'opposed': 0.27; 'message-id:@mail.gmail.com': 0.27; 'comparison': 0.29; 'could': 0.32; 'retain': 0.33; 'to:addr :python-list': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'ben': 0.35; "won't": 0.35; 'something': 0.35; 'subject:: ': 0.38; 'skip:l 20': 0.38; 'performance': 0.39; 'to:addr:python.org': 0.39; 'believe': 0.69; 'consequences': 0.71; 'goal': 0.74; '2013': 0.84; 'effectively,': 0.84; 'snapshot': 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; bh=xueD2NISJXQtv6eBxtSUqSpae0h4GD3Ra3ZRri3rmNc=; b=ylxPJcx/LXiCfCROQqCdwtKMWj7j3KXLdOuM+QmHMDAk1b/zuYSjAMGmIlR8as2dBI gDwcdWkLd5ujVkTKzOl29Writu8siQ6M1Lp2e6QcOfv+6Kt6pEYBQqmTPyDfrDeR6x8Q 6UQfEvm7rpVikIo2+zURd3Y47jK6m5BQz8wc/KNEiD+8B5Wz3LtcCPknNSMiT5jUSjWf T58RXZjXJq0yGKIYcTuN49M3KdfjI8ao8ql/7p/yW7kFnXLI9QKQ+EbXRXVllaaY54eO fAuAHoANZhjZiA/wWcANVG0xJ/mr6QGUM8Jan6koxeiHgdQy5I+OezoZGanyR9j7XLnX AaHg==
MIME-Version 1.0
X-Received by 10.52.88.197 with SMTP id bi5mr10017329vdb.58.1362586976928; Wed, 06 Mar 2013 08:22:56 -0800 (PST)
In-Reply-To <b281a2a6-5822-45c7-bf69-c80c738ef92c@googlegroups.com>
References <b281a2a6-5822-45c7-bf69-c80c738ef92c@googlegroups.com>
Date Thu, 7 Mar 2013 03:22:56 +1100
Subject Re: Creating an object that can track when its attributes are modified
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2949.1362586985.2939.python-list@python.org> (permalink)
Lines 15
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1362586985 news.xs4all.nl 6969 [2001:888:2000:d::a6]:40417
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:40643

Show key headers only | View raw


On Thu, Mar 7, 2013 at 3:07 AM, Ben Sizer <kylotan@gmail.com> wrote:
> I also believe that this won't catch modification to existing attributes as opposed to assignments: eg. if one of the attributes is a list and I append to it, this system won't notice. Is that something I can rectify easily?

The only way you could detect mutation of one of its attributes is
with that object's assistance. Effectively, you would need to have a
subclass of list/dict/tuple/whatever that can respond to the change.
Alternatively, you could retain a deep copy and do a comparison at
time of rollback; this, however, would have annoying consequences wrt
performance and other references and such.

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?

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Creating an object that can track when its attributes are modified Ben Sizer <kylotan@gmail.com> - 2013-03-06 08:07 -0800
  Re: Creating an object that can track when its attributes are modified Chris Angelico <rosuav@gmail.com> - 2013-03-07 03:22 +1100
    Re: Creating an object that can track when its attributes are modified Ben Sizer <kylotan@gmail.com> - 2013-03-06 08:56 -0800
      Re: Creating an object that can track when its attributes are modified Chris Angelico <rosuav@gmail.com> - 2013-03-07 04:03 +1100
      Re: Creating an object that can track when its attributes are modified 88888 Dihedral <dihedral88888@googlemail.com> - 2013-03-06 13:07 -0800
      Re: Creating an object that can track when its attributes are modified 88888 Dihedral <dihedral88888@googlemail.com> - 2013-03-06 13:07 -0800
    Re: Creating an object that can track when its attributes are modified Ben Sizer <kylotan@gmail.com> - 2013-03-06 08:56 -0800
      Re: Creating an object that can track when its attributes are modified Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-07 00:07 +0000
        Re: Creating an object that can track when its attributes are modified Ben Sizer <kylotan@gmail.com> - 2013-03-06 16:26 -0800
          Re: Creating an object that can track when its attributes are modified Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-08 18:50 +0000
  Re: Creating an object that can track when its attributes are modified Lele Gaifax <lele@metapensiero.it> - 2013-03-06 17:56 +0100
  Re: Creating an object that can track when its attributes are modified Schneider <js@globe.de> - 2013-03-07 13:21 +0100

csiph-web