473,399 Members | 2,278 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

detecting property modification

Howdy,

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
metaclasses.
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).

Regards
Dec 21 '07 #1
0 767

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

Similar topics

3
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...
0
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...
25
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...
2
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...
6
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...
1
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
79
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...
4
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...
0
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...
9
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.