Message27
Calling the constructor of a PyObject subclass with arguments will
cause the __repr__() methods to be ignored. JimH hinted that this
would be solved in jpython1.1 (see below).
JPython 1.1beta1 on java1.2.1
Copyright ® 1997-1999 Corporation for National Research Initiatives
>>> import test142j
>>> a = test142j([1.1, 1.2, 1.3])
>>> print len(a)
3
>>> print repr(a)
test142j@442a4904
>>> b = test142j.new([1.1, 1.2, 1.3, 1.4])
>>> print len(b)
4
>>> print repr(b)
1.1, 1.2, 1.3, 1.4,
>>>
-------------------- test142j.java --------------------
import org.python.core.*;
public class test142j extends PyObject {
double[] data;
int len;
public test142j(double[] darray) {
data=darray;
len=data.length;
}
public int __len__() {
return len;
}
public PyString __repr__() {
StringBuffer buf = new StringBuffer();
for(int i=0; i<len; i++) {
buf.append(data[i]);
buf.append(", ");
}
return new PyString(buf.toString());
}
public static test142j new$(double[] array) {
return new test142j(array);
}
}
-------------------- END --------------------
On 19981208, JimH wrote:
Your problem is that under the current JPython release, you can't
directly call the constructors of classes that subclass from PyObject
and get the expected result. This is considered a clear design
mistake in JPython and will be fixed in 1.1.
|
|
Date |
User |
Action |
Args |
2008-02-20 17:16:38 | admin | link | issue222795 messages |
2008-02-20 17:16:38 | admin | create | |
|