OMHO changing directly the PyString class is a bit complex and risky.
Doesn't a simple inheritance solve your problem?
from java.lang import *

class MyString(str): def __init__(self,ss): str.__init__(self,ss) self.ss = ss def islike(self,sp):
stmp = String(self.ss)
return stmp.compareTo(sp)

Now, if you _REALY_ want to change directly the PyString file you can for example adding this class:
class exposed_islike extends PyBuiltinMethodNarrow {

            exposed_islike(PyObject self,PyBuiltinFunction.Info info) {

            public PyBuiltinFunction bind(PyObject self) {
                return new exposed_islike(self,info);

            public PyObject __call__(PyObject arg0) {
            	try {
            		return new PyInteger(((PyString)self).str_islike(arg0.asStringOrNull(0)));
            	catch (PyObject.ConversionException e) {
                    String msg;
                    switch (e.index) {
                    case 0:
                        msg="expected a string";
                    throw Py.TypeError(msg);

// get a look to PyMethodDescr.java
 dict.__setitem__("islike",new PyMethodDescr("islike",PyString.class,0,1,new exposed_islike(null,null)));
Then you have to implement the function str_islike:
final int str_islike(String s){
    	return string.compareTo(s);

Hope that matches your requirements.
Note that I'm new in Jython too.


On 6/18/07, sbarik08 < suvenduse@gmail.com> wrote:

Hi All,
       I m realatively new to jython. I am a java programmer.  My
requiremnet is as follows.
I want to extend the PyString class to create a String type with additon
methods like islike() etc.Each time i m doing so and trying to evaluate the
newly created function i m getting attribute error.Can anyone plz help me
out specifying the exact procedure to extend PyString class ...
View this message in context: http://www.nabble.com/Extending-PyString-tf3942089.html#a11181575
Sent from the jython-dev mailing list archive at Nabble.com.

This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
Jython-dev mailing list