473,326 Members | 2,655 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,326 software developers and data experts.

class property methods getting called only once

In the following code, I could not find out why the set and get methods
are not called once I set the property.

>>class Test:
.... def __init__(self):
.... self._color = 12
.... def _setcolor(self,value):
.... print 'setting'
.... self._color = value
.... def _getcolor(self):
.... print 'getting'
.... return self._color
.... color = property(_getcolor,_setcolor)
....
>>a = Test()
a.color
getting
12
>>a.color = 22
a.color
22

For some reason the set method is not getting called at all, Anybody
has any clue?

thanks.
--
Suresh

Dec 4 '06 #1
1 1285
>On 3 Dec 2006 21:24:03 -0800, jm*******@no.spam.gmail.com
<jm*******@gmail.comwrote:
In the following code, I could not find out why the set and get methods
are not called once I set the property.

>class Test:
... def __init__(self):
... self._color = 12
... def _setcolor(self,value):
... print 'setting'
... self._color = value
... def _getcolor(self):
... print 'getting'
... return self._color
... color = property(_getcolor,_setcolor)
...
>a = Test()
a.color
getting
12
>a.color = 22
a.color
22

For some reason the set method is not getting called at all, Anybody
has any clue?

thanks.
property can only be used in New Style Class. So you should write your Test as:

class Test(object):

And try again.

--
I like python!
UliPad <<The Python Editor>>: http://wiki.woodpecker.org.cn/moin/UliPad
My Blog: http://www.donews.net/limodou
Dec 4 '06 #2

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

Similar topics

18
by: John M. Gabriele | last post by:
I've done some C++ and Java in the past, and have recently learned a fair amount of Python. One thing I still really don't get though is the difference between class methods and instance methods. I...
3
by: Pavils Jurjans | last post by:
Hallo, Is there some decent way how to get the object class name in a string format? Currently I use this: function getClassName(obj) { if (typeof obj != "object" || obj === null) return...
7
by: Koda | last post by:
What is the difference between class fields and class properties? Thanks Mike
2
by: David Adams | last post by:
Hi, I am afraid I am asking a very basic question, or just something that is not possible. I have a WinForm app that contains a Form (Form A), and then 20-30 UserControls/WinForms that are...
9
by: Brian Henry | last post by:
If i inherite a queue class into my class, and do an override of the enqueue member, how would i then go about actually doing an enqueue of an item? I am a little confused on this one... does over...
16
by: Allen | last post by:
I have a class that returns an arraylist. How do I fill a list box from what is returned? It returns customers which is a arraylist but I cant seem to get the stuff to fill a list box. I just...
7
by: WXS | last post by:
Vote for this idea if you like it here: http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=5fee280d-085e-4fe2-af35-254fbbe96ee9...
5
by: Andy B | last post by:
I am trying to figure out how to make an object instance available for all methods of a class. I tried to do something like this: public class test { TheObject Instance = new TheObject();...
2
by: Dinsdale | last post by:
We have created a object library that implements the INotifyPropertyChanged.PropertyChanged to bubble changes up to higher level classes. For instance, we have a person class that can have...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.