> Oh wait, I get it - you are passing bound methods to property(). So um is
> bound to the instance when you access self.getA. Use Strange.getA instead of
> self.getA, then use the normal signatures.
Ahh... I get it.
> But I don't get why you are doing this at all?
Because some of the objects
Your method signatures are off. Should be
def getA(self):
def setA(self, value)
So when you write self.a = 20 you are passing self as the um parameter.
Actually I don't know why you don't get an exception for passing too many
arguments?
And you don't need setattr, just write
Strange.a = propert
Liam Clarke wrote:
>>http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/410698
>
>
> Thanks Kent. Just looking at that above recipe, I'm not too sure how
> the @ decorators work.
>>From what I understand, it defines would turn apply() into a function
> that returns the various get/sets?
OK,
Ooer,
Well, I got setattr() and property() working together nicely, but with
a weird side effect.
class Strange(object):
def getA(um, self):
print "What is", um
return self.__a
def setA(um, self, value):
print um, "turns up here as well."
self.__a = value
Hi,
> You might want to learn more about the whole property mechanism then.
> property() is actually a bit of sugar over a deeper mechanism. Also there is
> an interesting idiom for creating properties using @apply (in Python 2.4) -
> look for Benji York's comment in this recipe:
> http://aspn
mailing list wrote:
> Hi Kent,
>
>
>
>> >>> class foo(object):
>> ... __slots__ = ['x', 'y']
>> ...
>> >>> f=foo()
>> >>> f.x=1
>> >>> f.y=2
>> >>> f.z=3
>>Traceback (most recent call last):
>> File "", line 1, in ?
>>AttributeError: 'foo' object has no attribute 'z'
>>
>>Take a look at
>>htt
Hi Kent,
>
> >>> class foo(object):
> ... __slots__ = ['x', 'y']
> ...
> >>> f=foo()
> >>> f.x=1
> >>> f.y=2
> >>> f.z=3
> Traceback (most recent call last):
> File "", line 1, in ?
> AttributeError: 'foo' object has no attribute 'z'
>
> Take a look at
> http://www.python.org/2.2.3/des
mailing list wrote:
> Hi all,
>
> I'm just looking for a quick runthrough on the differences between new
> style classes and the old ones, and how to use the new ones.
>
> Also, how exactly do you use __slots__? I've got a 6000 object
> collection, and apparently using __slots__ will save memory,
Hi all,
I'm just looking for a quick runthrough on the differences between new
style classes and the old ones, and how to use the new ones.
Also, how exactly do you use __slots__? I've got a 6000 object
collection, and apparently using __slots__ will save memory, but only
those attributes specifi