From: Kevin B. <kb...@ca...> - 2002-03-26 18:52:20
|
I'd be hesitant to do this. A couple of reasons: - In general, the Python string formatting idioms are preferred: Instead of: print "text " + obj + ", " + obj2 + "/" + obj3 use: print "text %s, %s/%s" % (obj, obj2, obj3) or: print "text %(obj)s, %(obj2)s/%(obj3)s" % vars() - The proposed enhancement for Java instances would cause Python instances & java instances to behave differently: t = 5 s = Object() print "text" + t + " " + s ## error kb Anthony Eden wrote: > Currently, in Jython, using any arbitrary Java object aside from a java.lang.String, the following fails: > > print "text" + obj > > With the message: TypeError: __add__ nor __radd__ defined for these operands > > But the following works: > > print "test", obj > > > Would the Jython implementers consider modifying the PyJavaInstance class with something similar to: > > public PyObject __add__(PyObject object) { > return __str__ + object.__str__(); > } > > So that the + notation as used in Java works properly? I am not sure if the code I provided above is correct as I am > not intimately familiar with the Jython source. I am also not sure if this has been discussed before: the mailing list > archives provided at the Jython.org site do not have search facilities (AFAICT) and I was unable to find anything about > it in my mail application (back to 7/21/2001), so I apologize ahead of time if it has. > > Sincerely, > Anthony Eden > > > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users |