Message5410
This is a bit strange, here is the sample:
class Attr(object):
def __init__(self, name):
self.name = name
def __set__(self, instance, value):
instance.__dict__[self.name] = value
class Test(object):
attr = Attr('attr')
def test(self):
self.attr = 5
t = Test()
print t.attr
t.test()
print t.attr
In python, if you have a newstyle object called x, and in some point define the attribute __dict__["x"] as 5 then getting the value of x. So in python that program would return:
<__main__.Attr object at 0x7f1b820b7f90>
5
On jython it returns:
<__main__.Attr object at 0x1>
<__main__.Attr object at 0x1>
A workaround would be to add a __get__ method something like this:
def __get__(self, instance, owner):
return instance.__dict__[self.name]
But for compatibility it would be nice to change this.
Thanks! |
|
Date |
User |
Action |
Args |
2010-01-06 13:19:12 | iamedu | set | recipients:
+ iamedu |
2010-01-06 13:19:12 | iamedu | set | messageid: <1262783952.08.0.594813559384.issue1534@psf.upfronthosting.co.za> |
2010-01-06 13:19:11 | iamedu | link | issue1534 messages |
2010-01-06 13:19:10 | iamedu | create | |
|