From: Humbel O. <Otm...@bi...> - 2001-09-04 16:01:00
|
[ John Goerzen ] >=20 > Another question (sorry about all of these!) >=20 > I'm porting more Java code to Jython. I've got a case like: >=20 > public static String myfunc(String id) >=20 > I'm unsure how to do a static method in Jython. Do I declare it in my > .py oustide the class: area with a @sig that has static in it? Just inside the class, but **without** the self parameter. Given file Foo.py: class Foo: # constructor def __init__( self ): pass =20 # an instance method def fooMethod( self, argument ): print "called fooMethod(%s)" % argument =20 # a 'static' method def myfunc( id ): print "called myfunc(%s)" % id Then you can call myfunc 'statically': jython -i Foo.py >>> Foo.myfunc( "hello" ) called myfunc(hello) >>> foo =3D Foo() >>> foo.fooMethod( "hi" ) called fooMethod(hi) >>>=20 Hope this helps, Oti. |