|
From: Samuele P. <pe...@in...> - 2001-08-07 18:51:30
|
Hi.
I'm still a bit confused, how far is this (up to PyObject subclassing and
other not directly related issues) from what you would like?
<jc.py>
import new
class X:
def __init__(self,c):
self.c = c
def add(self,a,b):
return self.c*(a+b)
def mul(self,a,b):
return self.c*a*b
x=X(2)
print repr(x.__class__)
print X.add
print X.mul
print x.add(1,2)
print x.mul(3,2)
def jmerge(cls,jskel):
new_cls = new.classobj(cls.__name__,(jskel,cls),{})
new_cls.__module__ = cls.__module__
return new_cls
import Xj
X=jmerge(X,Xj)
x=X(2)
print repr(x.__class__)
print X.add
print X.mul
print x.add(1,2)
print x.mul(3,2)
print x.describe()
</jc.py>
Output:
<class __main__.X at 5783932>
<unbound method X.add>
<unbound method X.mul>
6
12
<class __main__.X at 3462044>
<java function add at 3199804>
<unbound method X.mul>
6
12
Xj(c=2)
Consider, Xj is the following java class:
public class Xj {
public int c;
public int add(int a,int b) {
return c*(a+b);
}
public String describe() {
return "Xj(c="+c+")";
}
}
regards, Samuele Pedroni.
|