From: Humbel O. <Otm...@bi...> - 2001-09-05 07:22:57
|
[ Kevin Butler ] > Jython 2.1a1 on java1.3.0 (JIT: null) > Type "copyright", "credits" or "license" for more information. > >>> class X: > ... def go( id ): > ... print "called:", id > ...=20 > >>> X.go( "asdf" ) > Traceback (innermost last): > File "<console>", line 1, in ? > TypeError: unbound method go() must be called with instance=20 > as first argument > >>> >=20 > The 'self' parameter is not a keyword - it is a convention. =20 > Methods on class X require an X instance: >=20 > >>> X.go( X() ) > called: <__main__.X instance at 5991085> > >>>=20 >=20 > What you can do is cheat in one of two ways: >=20 > class XGo: > """Callable object to act as a static method""" > def __call__( self, id ): > print "called XGo(%s)" % id >=20 > class XStatics: > def go( self, id ): > """Use the bound method as a static method""" > print "called XStatics.go(%s)" % id > # ... and other "static" methods >=20 >=20 > class X: > go =3D XGo() > __xstatics =3D XStatics() > go2=3D__xstatics.go > # ... and other static methods >=20 > X.go( "asdf" ) > X.go2( "zxcv") >=20 > Then executing that from emacs: >=20 > Jython 2.1a1 on java1.3.0 (JIT: null) > Type "copyright", "credits" or "license" for more information. > ## working on region in file d:/TEMP/python-289AX1... > >>> called XGo(asdf) > called XStatics.go(zxcv) > >>>=20 Please **apologize** for confusing things. I currently use both Jython and JPython in two (or more) buffers in emacs, and did not test my example with Jython 2.x, because I simply could not imagine that THIS behaviour could have changed - mea culpa ! Thank you very much for pointing out (and solving !) another upgrade issue. I am already thinking about the regex expression to find def()'s without self as first argument :-) best wishes, Oti. |