472,988 Members | 2,900 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,988 software developers and data experts.

detecting property modification


I think it is easier to explain my question with a short example:

class Body:
def __init__(self, pos):
self.__dict__['pos'] = pos

def __setattr__(self, name, value):
if name == 'pos':
print 'pos changed to', value

self.__dict__[name] = value
>>b = Body([0, 0])
b.pos = [3, 4]
pos changed to [3, 4]
b.pos[0] = 5 # How do I detect this in the Body?

I would like to print 'pos changed to [5, 4]' when pos is modified
with direct access to the pos object (i.e. b.pos[0] = 5)
My first instinct is to modify the Body's __dict__ by using
I don't have any experience with meta classes but from what I remember
this should be possible but I thought there could be a simpler way to
do this.

What is the Pythonic way to do this? Can anybody provide a short
example for either case (with or without metaclasses).

Dec 21 '07 #1
0 761

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Alessandro Crugnola *sephiroth* | last post by:
Hi, i'm using wxPython and wxTextStyled. How can I intercept document changes for active documents (for example modified with others external editors)? thanks in advance -- Alessandro...
by: Joăo Santa Bárbara | last post by:
Hi all, i´m doing a form to be Inherited, and inside it has a property that i create. that property is one class with several propertys ( simple ones integers and strings ) And in my...
by: Ryan Stewart | last post by:
I'm working on a project to collect web application usage statistics. What are the recommended ways of detecting whether a browser is JavaScript enabled and/or capable? Obviously I can write a...
by: Deano | last post by:
In my app I have lots of forms with data presented in various ways using all kinds of controls. Is there a simple way of detecting if the user has changed any data? I would like to do this so I...
by: mccoyn | last post by:
I have a header that is included from some files that use mscorlib and some that don't use it. One of the macros in this file uses the __pin keyword. When this header is compiled with a source file...
by: Paul W | last post by:
I'm having trouble detecting whether my Control is in DesignMode. I'm deriving a class from TreeView; Public Class ExplorerView Inherits TreeView ... End Class
by: VK | last post by:
I wandering about the common proctice of some UA's producers to spoof the UA string to pretend to be another browser (most often IE). Shouldn't it be considered as a trademark violation of the...
by: wardy | last post by:
Hi all, Looking for a bit of help with this one...I have a situation where I need to be able to determine the control that initiated a form's submit action in client-side Javascript. I am...
by: Hans Koller | last post by:
Hello group, I design a class to bind it to a property grid for easy modification of some settings. My problem is now that I want to raise an event when a settings has been changed. Thats not a...
by: timor.super | last post by:
Hi group, I've written a client/server application, using the dotnet sockets. In my server, I have a thread waiting for messages with : ret = currSocket.Receive(buffer, 1024,...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.